PHP readfile与file_get_contents

时间:2013-11-20 11:51:26

标签: php function filesystems readfile

我使用以下代码生成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);

我很想知道两个案件中发生了什么

1 个答案:

答案 0 :(得分:50)

Readfile会将文件直接读入输出缓冲区,而file_get_contents会将文件加载到内存中,当你回显结果时,使用2倍于readfile的内存有效地将数据从内存复制到输出缓冲区。