20170621/594a1f5054498.jpg

The best life is use of willing attitude, a happy-go-lucky life.

— Mr.Wang

头像

php readfile() 解决下载文件因时文件太大而无法找到文件或变成1k大小

发布时间:2017-06-21 15:25:04

发布作者:admin

3938

最近公司OA系统遇见了这个错误。

下载报表时数据量太大,文件达到了300多M,这时出现了“页面未找到”或"文件大小变成1k"的错误,开始以为是服务器文件不存在,后来看了下确实有的,然后尝试了多次,发现小文件是可以下载的。

于是确定是文件太大的原因。

set_time_limit(0);  
ini_set('memory_limit', '512M');  
header('Content-Type: application/octet-stream');  
header('Content-Disposition: attachment; filename='.basename($file));  
header('Content-Transfer-Encoding: binary');  
ob_end_clean();  
readfile($file);  

主要注意前面2个设置(根据情况自己设置内存大小)和 ob_end_clean();函数的调用。


相关文章:
  1. php排列组合函数(无重复)
  2. Linux反选删除文件
  3. node.js 进程守护forever
  4. Linux下PureFtpd的基本安装使用与超时问题解决