【发布时间】:2009-03-03 06:26:59
【问题描述】:
我有一个 PHP 脚本,可以从 db 创建一个 xml 文件。我想让脚本创建 xml 数据并立即使 .gzip 文件可供下载。你能给我一些想法吗?
谢谢!
【问题讨论】:
我有一个 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 module,
<?php
system('gzip filename.xml');
?>
【讨论】: