PHP读取文件与文件获取内容

PHP读取文件与文件获取内容,php,function,filesystems,readfile,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-t

我使用了以下代码来生成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_内容会将文件加载到内存中,当您回显结果时,数据将从内存有效地复制到输出缓冲区,使用的内存是readfile的2倍。

您的意思是文件内容正确吗?什么不工作?您是否尝试过将错误报告设置为适当的值并读取任何错误/警告消息?是的,我这样做了,它显示了一个带有单个\n@Shankar是的,文件内容是第一次工作的,所以可能重复是的,这是我观察到的,readfile在生成文件时试图抛出文件,但是文件获取内容要等到成功生成。