First, CHMOD the file so it'll be writeable by the server. I think CHMOD 666 is appropriate.
Then use this code to open the file:
(Begin)
Change this value to the name of the file.
$filename = "file.txt";
Fetch the lines of the file as an array.
$fileContent = file($filename);
Join the array elements into a string.
$fileContent = implode("", $fileContent);
Make it HTML-safe.
$fileContent = htmlentities($fileContent);
Print the textarea.
(This assumes you've already printed the <FORM> tag.)
print "<textarea name='fileContent' wrap='virtual'>$fileContent</textarea>\n";
Print a hidden input with the filename.
print "<input type='hidden' name='filename' value='$filename'>\n";
(End)
Then use this code to write it to the file when the user has modified the text and pressed the submit button:
(Begin)
Failsafe to make sure we actually have anything to write to the file.
if (isset($fileContent) && isset($filename))
{
Open the file for writing.
$file = fopen($filename, "w");
I'm not sure if this line is needed... I don't remember if characters
like " get a backslash added when posted by a form.
Try removing this line and see if " looks the same.
$fileContent = stripslashes($fileContent);
Write to the file.
fwrite($file, $fileContent);
Close the file.
fclose($file);
}
else
{
print "The file was not written to, because some variable was missing.";
}
(End)
fayhu wrote:
hey .
I want to put a exist file into the TEXTAREA ,then can be edited and save in the same filename.
How can I do .can you help me?
thx very much !