PDA

View Full Version : Automatically creating and saving a file to my server...


Chad Roe
05-21-2006, 05:44 AM
My administration system only allows me (administrator) to add new client accounts. Along with the other data, I add a URL that goes to the new client's main account page. The thing is, I have to manually create the actual page...

How do I automatically create, and then save, the actual page?

I assume I can have a generic template that is loaded into a php string, then inject the client specific parts, and then use php to save the file to my server in the appropriate location?

Any help on this will be greatly appreciated (I have a little experience with adding dynamic text to an image, and then saving the image as a new image on my server...if that helps with your answers).

<h1>
05-21-2006, 07:34 AM
$filename = "filename.html";
$filehandle = fopen($filename, 'w') or die("can't create or open file");
fwrite($filehandle, $content);
fclose($filehandle);
'w' will create the file, and replace the contents if it exists. Folder you are creating the new file must have write permissions.

If you want use templates, which I think is the best option here, you should check out Smarty template engine (http://smarty.php.net/), I use it and it's very useful when working with templates, and seperating (x)html from variables