Forum Moderators: open

Message Too Old, No Replies

SSI updated by an online form

         

MatthewHSE

8:36 pm on Jul 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm trying to get some regularly updated content on my site, but I'm not able to do it all myself. So, I want to make it easy for others to provide content.

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?

jatar_k

9:29 pm on Jul 21, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What language are you using to update the file?

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.

MWpro

9:48 pm on Jul 21, 2003 (gmt 0)

10+ Year Member



Yep php with fopen and fputs is the best way to do this. I just want to go one more up on the example just to show people unfamiliar with php just how easy this can be.

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.