国产精品成人VA在线观看,亚洲日韩在线中文字幕综合,亚洲AV电影天堂男人的天堂,久久人人爽人人爽人人av东京热

News新聞

業(yè)界新聞動態(tài)、技術(shù)前沿
Who are we?

您的位置:首頁      樂道系統(tǒng)FAQ      php readfile下載大文件失敗的解決方法

php readfile下載大文件失敗的解決方法

標(biāo)簽: 發(fā)布日期:2017-05-22 00:00:00 288

本文實例講述了php readfile下載大文件失敗的解決方法。分享給大家供大家參考,具體如下:

大文件有200多M,只下載了200K就提示下載完成,且不報錯。

原因是PHP內(nèi)存有限制,需要改為按塊下載,就是把大文件切塊后逐塊下載。

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