I am trying to open a text file and modify it then save it to the server What am I doing wrong? This does not work it give me errors, I did set the permissions on the file and directory to chmod 777:
Warning: fwrite(): supplied argument is not a valid stream resource in /usr/www/users/development/php/text editor/test.php on line 40
Warning: fclose(): supplied argument is not a valid stream resource in /usr/www/users/development/php/text editor/test.php on line 41
<html>
<?php
$filename="text.txt";
// Gets webpage into a string
$html = implode('', file('text.txt'));
echo $html;
?>
<body>
<form name="form1" method="post" action="test.php">
<textarea name="newfile" cols="30" rows="10"><? echo $html; ?></textarea>
<input type="submit" name="submit" value="submit">
</form>
</html>
<?
if ($submit)
{
$file = "$filename";
$fh = fopen($file, 'w+');
fwrite($fh, $newfile);
fclose($fh);
}
?>
Writing to a text file with php
Moderator: General Moderators
-
mccommunity
- Forum Commoner
- Posts: 62
- Joined: Mon Oct 07, 2002 8:55 am
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
Code: Select all
<?php
$file = $filename;
$fh = fopen($file, 'w+');
fwrite($fh, $newfile);
fclose($fh);
?>If you are just writing to a file then you can use "w" instead of "w+" and also remember that if you are using a windows system then you need to add "b" to the end of it... ie "wb" or "w+b"