Forum Moderators: open
What I want to do is create a text file on my server, then refer to it with ssi on the appropriate pages. The text file would be updated by a password-protected online form. The idea is to give the password only to one person, who's in charge of updating some portion of my content. Then they get to just fill in the form (which consists only of a textarea), the form updates the text file, and the content placed in the textarea is thus placed in my pages wherever I've used the ssi.
The problem is I can't figure out how to get the form to simply overwrite any data that's already in the text file it writes to. If it just appends text, then the whole idea falls apart.
Does anyone know a way I can do this? Or, is there an easier way to get the result I want?
in php you can use
$fp = fopen [ca.php.net]("filename.txt","w");
with the "w" flag it will
Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
In any language it should be a matter of how you open it.
Have the content of the textarea set to a variable ($content in this example). This code goes in the form action.
<?php
//open the file and give it write access
$file = fopen("filename.txt","w");
//write the content to the file
fputs($file,"$content");
//close the file
fclose($file);
?>
Not complicated at all, as you can see.
Then all you have to do is include filename.txt into the page where you want it to show up, like so
<?php include("filename.txt");?>
Then all you have to do is make sure your pages have .php extensions, or to edit your .htaccess to parse html as php.