首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >PHP readfile与file_get_contents

PHP readfile与file_get_contents
EN

Stack Overflow用户
提问于 2013-11-20 19:51:26
回答 1查看 36.2K关注 0票数 41

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

我很想知道这两种情况下发生了什么。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-20 19:55:44

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

票数 69
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20095175

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档