本文實例講述了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程序設計有所幫助。
新聞熱點
疑難解答
圖片精選