phpreadfile下载大文件失败解决方法,原因是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>";帝国CMS教程
织梦cms教程
discuz教程
ecshop教程
phpcms教程
wordpress教程
苹果cms教程
php教程
数据库教程
微信小程序教程
python教程
css教程
js教程
视频教程
电子书
热门推荐- 01 分享几个随机美女图api接口 3843热度
- 02 优学院自动刷课PHP代码 699热度
- 03 php文件限速下载示例代码 626热度
- 04 随机二次元图片API接口源码 557热度
- 05 php一键打包压缩目录文件代码示例 458热度
