Edit multiple txt-files script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SpritHansi
Forum Newbie
Posts: 2
Joined: Wed Jul 07, 2010 11:21 pm

Edit multiple txt-files script

Post 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 :-)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Edit multiple txt-files script

Post by requinix »

A starting point:

If you name your <textarea>s "content[]" then $_POST["content"] will be an array.
SpritHansi
Forum Newbie
Posts: 2
Joined: Wed Jul 07, 2010 11:21 pm

Re: Edit multiple txt-files script

Post by SpritHansi »

Hi!
Thanks, but can you please be more spesific. I doesn't understand PHP very well.... yet :?
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Edit multiple txt-files script

Post 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];
Post Reply