Skip to content

Instantly share code, notes, and snippets.

@sansumbrella
Created December 19, 2009 19:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sansumbrella/260223 to your computer and use it in GitHub Desktop.
php static page creation
<?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