我想使用 PHP 对我服务器上的文件进行 gzip 压缩。有没有人有输入文件并输出压缩文件的示例?
最佳答案
这段代码可以解决问题
// Name of the file we're compressing
$file = "test.txt";
// Name of the gz file we're creating
$gzfile = "test.gz";
// Open the gz file (w9 is the highest compression)
$fp = gzopen ($gzfile, 'w9');
// Compress the file
gzwrite ($fp, file_get_contents($file));
// Close the gz file and we're done
gzclose($fp);
关于php - 如何使用 PHP 创建 .gz 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6073397/