php rendering large zip file - memory limit reached

為{幸葍}努か 提交于 2019-11-29 12:37:21

Stream the download, so it doesn't choke on memory. Tiny example:

$handle = fopen("exampe.zip", "rb");
while (!feof($handle)) {
    echo fread($handle, 1024);
    flush();
}
fclose($handle);

Add correct output headers for downloading, and you should solve the problem.

PHP actually provides an easy method to output a binary file directly to Apache without stashing it in memory first via the readfile() function:

header('Content-Type: application/zip');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="file.zip"');
readfile('file.zip');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!