【发布时间】:2011-09-11 02:12:12
【问题描述】:
我尝试在 php.ini 中渲染一个 zip 文件。 代码:
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="file.zip"');
下载的文件,只有几个字节。这是一条错误消息:
<br />
<b>Fatal error</b>: Allowed memory size of 16777216 bytes exhausted (tried to allocate 41908867 bytes) in <b>/var/www/common_index/main.php</b> on line <b>217</b><br />
我不想增加 php.ini 中的 memory_limit。有哪些替代方法可以在不修改全局设置的情况下正确呈现大型 zip 文件?
【问题讨论】:
-
压缩包从哪里来?从磁盘还是动态创建?基本的解决方案是流式传输数据,这样您就不会同时将其全部保存在内存中。
-
你用什么函数来转储文件?你看过
readfile()吗? php.net/readfile
标签: php zip rendering memory-limit