我使用以下代码生成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倍内存从内存复制到输出缓冲区时。