Created
December 19, 2009 19:42
-
-
Save sansumbrella/260223 to your computer and use it in GitHub Desktop.
php static page creation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$base_url = "http://localhost/~username"; | |
$builder = new Build($base_url); | |
$source = "index.php?about"; | |
$target = "about.html"; | |
$builder->write_file($source, $target); | |
Class Build | |
{ | |
public $url; //base url | |
function Build($url="http://localhost/") | |
{ | |
$this->url = $url; | |
} | |
function write_file($source, $destination) | |
{ | |
$sourcepage = $this->url."/$source"; | |
echo "Grabbing html from $sourcepage<br/>"; | |
$dynamic_source = fopen($sourcepage, 'r'); | |
$targetfilename = "../$destination"; | |
if (!$dynamic_source) { | |
die("Unable to load $sourcepage"); | |
} | |
$htmldata = fread($dynamic_source, 1024*1024); | |
fclose($dynamic_source); | |
$tempfilename = "../tmp/$destination"; | |
echo "Writing temporary file to $tempfilename<br/>"; | |
$tempfile = fopen($tempfilename, 'w'); | |
if (!$tempfile) { | |
die("Unable to open temporary file $tempfilename for writing."); | |
} | |
fwrite($tempfile, $htmldata); | |
fclose($tempfile); | |
echo "Copying to final location: $targetfilename<br/>"; | |
//you might run into permissions errors here | |
copy($tempfilename, $targetfilename); | |
echo "$destination updated<br/>"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment