您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php大文件下载失败解决方案

2024/3/1 23:57:33发布26次查看
这篇文章主要介绍了php readfile下载大文件失败的解决方法,涉及php针对大文件的分割及逐块下载操作实现技巧,需要的朋友可以参考下
本文实例讲述了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大文件下载失败解决方案的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product