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
Siryx
Forum Newbie
Posts: 11 Joined: Tue Jul 26, 2005 9:58 am
Post
by Siryx » Tue Jul 26, 2005 10:03 am
I am trying to modify a text file, I can open and add lines in the bottom, but i want to modify the entire document. Here is the code, i put the text in a comment box, and i want to apply the changes when i hit a sumbit botton.
Code: Select all
<?php
$filename = 'alo.txt';
$fp = fopen($filename, "r");
$text = fread($fp, filesize($filename));
fclose($fp);
$modify = $_POST["txt_comment"];
$fw = fopen ($filename, "a");
fwrite($fw, $modify);
fclose($fw);
?>
<html>
<head>
<title>Text mod.</title>
</head>
<body>
<form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="POST" >
<textarea name="txt_comment" value="" cols="40" rows="10"><?php echo $text; ?></textarea>
<br><br><input name="Submit" type="submit" value="Submit">
</form>
</body>
</html>
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Tue Jul 26, 2005 10:22 am
Use "w" instead of "a".
BTW... you're missing the quotes from PHP_SELF
Siryx
Forum Newbie
Posts: 11 Joined: Tue Jul 26, 2005 9:58 am
Post
by Siryx » Tue Jul 26, 2005 11:04 am
d11wtq wrote: Use "w" instead of "a".
BTW... you're missing the quotes from PHP_SELF
now i can modify, thanks man.
i got one last question, how can i send to a confirmation page after I modify the file? i try many ways, but no one work. thanks!
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Tue Jul 26, 2005 11:08 am
Siryx wrote:
how can i send to a confirmation page after I modify the file?
Code: Select all
if (fwrite($fw, $modify) !== FALSE)
echo 'Confirmed !';
Siryx
Forum Newbie
Posts: 11 Joined: Tue Jul 26, 2005 9:58 am
Post
by Siryx » Tue Jul 26, 2005 11:25 am
anjanesh wrote: Siryx wrote:
how can i send to a confirmation page after I modify the file?
Code: Select all
if (fwrite($fw, $modify) !== FALSE)
echo 'Confirmed !';
Warning: fwrite(): 3 is not a valid stream resource in localhost\text.php on line 12