当前位置: 首页 » 产品 » 出口外贸 » 正文

php readfile下载大文件失败怎么办

放大字体  缩小字体 发布日期: 2024-10-05 05:19   来源:http://www.baidu.com/  作者:无忧资讯  浏览次数:32
核心提示:大文件有200多M,只下载了200K就提示下载完成,且不报错。原因是PHP内存有限制,需要改为按块下载,就是把大文件切块后逐块下载

大文件有200多M,只下载了200K就提示下载完成,且不报错。

原因是PHP内存有限制,需要改为按块下载,就是把大文件切块后逐块下载

if (file_exists($file)) { if (FALSE!==($handler=fopen($file, 'r'))) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: chunked'); //changed to chunked header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); //header('Content-Length: ' . filesize($file)); //Remove //Send the content in chunks while(false !==($chunk=fread($handler,4096))) { echo $chunk; } } exit; } echo "<h1>Content error</h1><p>The file does not exist!</p>";

 
 
[ 产品搜索 ]  [ 加入收藏 ]  [ 告诉好友 ]  [ 打印本文 ]  [ 违规举报 ]  [ 关闭窗口 ]

 

 
推荐图文
推荐产品
点击排行
    行业协会  备案信息  可信网站