PHP读取文件与file_get_contents [英] PHP readfile vs. file_get_contents
本文介绍了PHP读取文件与file_get_contents的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用下面的代码来生成zip
// push下载zip
header('Content -type:application / zip');
header('Content-Disposition:attachment; filename =''。$ zip_name。'');
readfile($ zip_name);
此代码正常工作,但由于未知原因, b
//推送下载zip
头('Content-type:application / zip');
header('Content-Disposition:attachment; filename =''。$ zip_name。'');
echo file_get_contents($ zip_name);
我很好奇在这两种情况下发现了什么
<解决方案读取文件将直接读取文件到输出缓冲区,file_get_contents将文件加载到内存中,当您回显结果数据从内存复制到输出缓冲区有效地使用了2倍的readfile的内存。
I have used following code to generate zip
// push to download the zip
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$zip_name.'"');
readfile($zip_name);
this code works fine but for unknown reasons was not working until I tried
// push to download the zip
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$zip_name.'"');
echo file_get_contents($zip_name);
I am curious about finding what is happening in both the cases
解决方案
Readfile will read the file directly into the output buffer, and file_get_contents will load the file into memory, when you echo the result the data is copied from memory to the output buffer effectively using 2 times the memory of readfile.
这篇关于PHP读取文件与file_get_contents的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文