[英]How can I offer a gzipped xml file for download using PHP
我有一个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');
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.