Reputation: 169
I use this script to automatically save a PHP-file into a HTML file on my server:
<?php
$page=file_get_contents('http://yourdomain.com/index.php');
$fp=fopen('index.html','w+');
fputs($fp,$page);
fclose($fp);
?>
How can I get the server to also save a Gzipped version of index.php on the server?
The goal is to have the following files in the folder:
turn-indexphp-into-indexhtml-and-indexgz.php
index.php
index.html
index.gz
Upvotes: 2
Views: 1115
Reputation: 10351
If you can only access the page by URL (ie. it is not a file on your own server), as pointed out by a few commenters - you will only be able to access the output of the PHP/ASP/Whatever file.
If it is not a Local File
<?php
$theUrl = 'http://www.server.com/filename.htm';
$theOutput = file_get_contents( $theUrl );
$outBase = preg_replace( '/[^\d\w]/' , '_' , $theUrl );
// Output standard HTML file (Filename may be clunky, but, up to you to fix that)
$outHTM = $outBase.'.htm';
file_put_contents( $outHTM , $theOutput );
// Output a GZipped version of same
$outGZ = $outBase.'.htm.gz';
$theOutput = gzencode( $theOutput , 9 );
file_put_contents( $outGZ , $theOutput );
?>
If it is a local file, then you can do the above, but also...
<?php
$theLocalFile = '/somefolder/anotherfolder/index.php';
$theLocalContent = file_get_contents( $theLocalFile );
$localBase = preg_replace( '/[^\d\w]/' , '_' , $theLocalContent );
// Save an uncompressed copy
$outLocal = $localBase.'.php';
file_put_contents( $outLocal , $theLocalContent );
// Save a GZipped copy
$outGZ = $localBase.'.php.gz';
$theOutput = gzencode( $theLocalContent , 9 );
file_put_contents( $outGZ , $theOutput );
?>
Upvotes: 3