...

View Full Version : Saving a PHP page as a static HTML page



captjeffc
01-09-2006, 10:59 PM
I work in Dreamweaver 8 and can produce dynamic PHP page with no problem. Now I would like to be able to save these pages as a static HTML page in a folder on the server. My old programmer said this could be done using the fopen command.

I would like to be able to specify the folder, as well as the file names prefix, the unique id will complete the files name.

I blend Dreamweaver pages with hardcoded code to get what I need. I just done know where to go from here.

Any help is appreciated.

Element
01-09-2006, 11:47 PM
probably something like:





$page = file_get_contents($_SERVER['PHP_SELF']);
$ext = "htm";
$newfilename = substr(md5(uniqid()), 0, 8) . "." . $ext;
$path = "_tmp/";
if($handle=fopen($path . $newfilename, "a+")) {
if(fputs($page, $handle)) {
echo "Static HTML file created.<br><a href=\"http://" . $_SERVER['HTTP_HOST'] . "/" . $path . $newfilename . "\" target="_blank">" . $newfilename . "</a>";
}
}



You can try something like that, edit it around though of course.

Velox Letum
01-10-2006, 01:40 AM
Careful, you might get an infinite loop with that file. Use a dedicated file to open others.


$url = $_GET['page'];

$tmpurl = explode("?", basename($url));

if ($tmpurl[0] == $_SERVER['PHP_SELF']) {
die('Improper page. Cannot open self.');
}

$page = file_get_contents($url); // Will only work if remote file opens are allowed
$ext = "htm";
$newfilename = substr(md5(uniqid()), 0, 8) . "." . $ext;
$path = "_tmp/";
if($handle=fopen($path . $newfilename, "a+")) {
if(fputs($page, $handle)) {
echo "Static HTML file created.<br><a href=\"http://" . $_SERVER['HTTP_HOST'] . "/" . $path . $newfilename . "\" target="_blank">" . $newfilename . "</a>";
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum