《PHP應(yīng)用:php readfile下載大文件失敗的解決方法》要點(diǎn):
本文介紹了PHP應(yīng)用:php readfile下載大文件失敗的解決方法,希望對您有用。如果有疑問,可以聯(lián)系我們。
PHP實例本文實例講述了php readfile下載大文件失敗的解決方法.分享給大家供大家參考,具體如下:
PHP實例大文件有200多M,只下載了200K就提示下載完成,且不報錯.
PHP實例原因是PHP內(nèi)存有限制,需要改為按塊下載,就是把大文件切塊后逐塊下載.
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實例更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php文件操作總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
PHP實例希望本文所述對大家PHP程序設(shè)計有所幫助.
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/764.html