搜索您想要的文章


phpreadfile下载大文件失败解决方法

作者:Admin采集插件 时间:2023-04-08 浏览:293 分类:php教程 来源:互联网收录

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>";


本文章来自互联网,有问题请联系QQ:1739635


免责声明:1.凡本站注明“来源:XXX(非CMS自动采集助手)”的作品,均转载自其它媒体,所载的文章、图片、音频视频文件等资料的版权归版权所有人所有,如有侵权,请联系1321198484@qq.com处理;2.凡本站转载内容仅代表作者本人观点,与CMS自动采集助手无关。