我使用以下代码来生成 zip
// push to download the zip
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$zip_name.'"');
readfile($zip_name);
这段代码工作正常,但由于未知原因在我尝试之前无法工作
// push to download the zip
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$zip_name.'"');
echo file_get_contents($zip_name);
我很好奇这两种情况发生了什么
readfile 会将文件直接读入输出缓冲区,file_get_contents 会将文件加载到内存中,当您回显结果时,数据会从内存复制到输出缓冲区,有效使用 readfile 内存的 2 倍。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)