php - 如何使用 PHP 创建 .gz 文件?

标签 php compression gzip

我想使用 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/

相关文章:

php - Kohana PHP - 具有共享模型的多个应用程序

Java Deflater,现在和将来的结果相同(确定性)

linux - 在APACHE中的哪个.htaccess文件中(OS : Linux centos) server do i need to update

python - 在 Python 中获取 tar 文件夹内容的文件名

python - 压缩编解码器如何在 Python 中工作?

asp.net - 在 Asp.net mvc 中 gzip 和缓存静态图像的最佳方法是什么

PHP 错误 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax

php - 在任意正则表达式中插入正向后向模拟字节偏移的后果

c++ - 使用全局词典中的常用短语分别压缩各行文本

php - 用于 PHP session 存储的最佳 MySQL 存储引擎