Page 1 of 1

Edit multiple txt-files script

Posted: Wed Jul 07, 2010 11:54 pm
by SpritHansi
Hi!
I need help with a script where I can edit multiple txt-files from a folder.
I have this script:
processscript.php

Code: Select all

<?
$fn = 'file_1.txt';
$content = stripslashes($_POST['content']);
$fp = fopen($fn,"w") or die ("Error opening file in write mode!");
fputs($fp,$content);
fclose($fp) or die ("Error closing file!");
echo "<meta http-equiv=\"refresh\" content=\"0; url=form.php\" />\n";
?>
and form.php

Code: Select all

<form action="processscript.php" method="post">
<textarea rows="6" cols="30" name="content">
<?
$fn = 'file_1.txt';
print htmlspecialchars(implode("",file($fn)));
?> 
</textarea><br>
<input type="submit" value="Lagre"> 
</form>
All txt-files are listet like this:
textfile_1.txt
textfile_2.txt
textfile_3.txt
and it's max 10 lines in every file.

Can someone please help me :-)

Re: Edit multiple txt-files script

Posted: Thu Jul 08, 2010 12:07 am
by requinix
A starting point:

If you name your <textarea>s "content[]" then $_POST["content"] will be an array.

Re: Edit multiple txt-files script

Posted: Thu Jul 08, 2010 7:44 am
by SpritHansi
Hi!
Thanks, but can you please be more spesific. I doesn't understand PHP very well.... yet :?

Re: Edit multiple txt-files script

Posted: Thu Jul 08, 2010 10:50 am
by Jade
Give each of your textareas a different name, otherwise you'll need to reference them like this:

Code: Select all

$content = $_POST['content'];

echo $content[0];
echo $content[1];