Writing to a text file with php
Posted: Fri Jan 23, 2004 1:37 pm
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);
}
?>
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);
}
?>