题
我有一个PHP脚本,可以从db创建一个xml文件。我想让脚本创建xml数据并立即生成.gzip文件供下载。你能给我一些想法吗?
谢谢!
解决方案
您可以使用 gzencode 功能轻松应用gzip压缩。
<?
header("Content-Disposition: attachment; filename=yourFile.xml.gz");
header("Content-type: application/x-gzip");
echo gzencode($xmlToCompress);
其他提示
这样的东西?
<?php
header('Content-type: application/x-gzip');
header('Content-Disposition: attachment; filename="downloaded.gz"');
$data = implode("", file('somefile.xml'));
print( gzencode($data, 9) ); //9 is the level of compression
?>
如果您没有 gzip模块,
<?php
system('gzip filename.xml');
?>
不隶属于 StackOverflow