我使用此脚本自动将 PHP 文件保存到服务器上的 HTML 文件中:
<?php
$page=file_get_contents('http://yourdomain.com/index.php');
$fp=fopen('index.html','w+');
fputs($fp,$page);
fclose($fp);
?>
我怎样才能让服务器在服务器上保存index.php的Gzipped版本?
目标是在文件夹中包含以下文件:
将indexphp-into-indexhtml-and-indexgz.php
index.php
index.html
index.gz
最佳答案
如果您只能通过 URL 访问该页面(即它不是您自己服务器上的文件),正如一些评论者所指出的那样 - 您将只能访问 PHP/ASP/Whatever 的输出文件。
如果不是本地文件
<?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 );
?>
如果是本地文件,那么就可以进行上述操作,而且...
<?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 );
?>
关于php - 使用 PHP gzipp 在服务器上保存 gzip 压缩的 html 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5175359/