0
我使用PHP腳本下載一個20MB的文件如下:PHP文件下載問題:服務器死機了幾分鐘,當用戶取消下載,然後重試
(文件路徑&名在腳本中先前設置)
$fullPath = $filepath.$filename;
if ($fd = fopen($fullPath, "r")) {
// http headers for zip downloads
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($fullPath));
while(!feof($fd)) {
echo(fread($fd, 1024*8));
flush();
if (connection_status()!=0) {
fclose($fd);
die();
}
}
}
fclose($fd);
exit();
它工作正常,如果下載完成,但如果下載用戶取消,而他們點擊鏈接重新下載,服務器是幾分鐘完全沒有反應,然後下載將開始。似乎它正在等待腳本超時...但不是「if(connection_status()!= 0)...」部分應該是該腳本?
任何幫助,非常感謝!先謝謝你!
使用readfile代替@ http://php.net/manual/en/function.readfile.php –
不['ignore_user_abort'](http://php.net/manual/en/function.ignore- user-abort.php)必須與'connection_status'配合使用? –