2014-02-11 16 views
0

我有一個小小的下載腳本安裝在這裏,它運作良好有時。我已經將問題縮小到僅在大多數時間發送的響應標題,並且當它們不發生什麼時,它會要求我下載文件,除非它的名稱在磁盤上,並且它被下載爲「應用程序/八位字節流」。 這裏有我發送php下載不一致的行爲

header('Content-Description: File Transfer'); 
header('Content-Disposition: attachment; filename="'.$file->logical_name.'"'); 
header('Content-Type: "'.$mime.'"'); 
header("Content-Length: ".filesize($this->file)); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header('Cache-Control: no-store, no-cache, must-revalidate'); 
header('Pragma: no-cache'); 
readfile($this->file); 

所以要清楚我的問題的頭文件信息只被有時發送,當他們沒有讓我的問題,這是沒有任何有關文件的信息被因此它發送下載作爲weired命名(如磁盤)「應用程序/八位字節流」

UPDATE

這dosnt使用更小文件讀取日之前發生的圍繞小於100KB

回答

0

刷新所有的輸出e文件解決了這個問題。 看來,關鍵是確保所有那些標題tyring下載的文件之前,實際發送(讀取與ReadFile的文件())

header('Content-Description: File Transfer'); 
header('Content-Disposition: attachment; filename="'.$file->logical_name.'"'); 
header('Content-Type: "'.$mime.'"'); 
header('Content-Length:'.filesize($this->file)); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header('Cache-Control: no-store, no-cache, must-revalidate'); 
header('Pragma: no-cache'); 
flush(); 
readfile($this->file); 

加入的flush()函數解決了這個問題。注意我沒有啓動一個帶有ob_start的緩衝區,所以我沒有做ob_flush,但在這種情況下你可以做到這一點