PHP readfile vs. file_get_contents

别说谁变了你拦得住时间么 提交于 2019-11-26 11:20:10

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/20095175/php-readfile-vs-file-get-contents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!