如何使用PHP提供一个可下载的gzipped xml文件

3

我有一个PHP脚本,可以从数据库中创建XML文件。 我希望该脚本在创建XML数据后立即生成可供下载的.gzip文件。 你能给我一些想法吗?

谢谢!

3个回答

13

你可以使用gzencode函数轻松应用gzip压缩。

<?
header("Content-Disposition: attachment; filename=yourFile.xml.gz");
header("Content-type: application/x-gzip");

echo gzencode($xmlToCompress);

2

你想要这样的翻译吗?

<?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
?>

0

如果您没有gzip模块可用,

<?php

  system('gzip filename.xml');

?>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接