Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
php static page creation
$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);
$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);
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
You can’t perform that action at this time.