本文实例讲述了php readfile下载大文件失败的解决方法。分享给大家供大家参考,具体如下:
大文件有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>";
以上就是php大文件下载失败解决方案的详细内容,更多请关注php中文网其它相关文章!
![php中文网最新课程二维码](/static/images/article_wechat2021.jpg?1111)
声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
- 上一篇:PHP访问者模式与组合模式详解
- 下一篇:PHP文件的读写介绍
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论