2013-11-21 76 views
1

哪些頭文件對於強制下載和哪些頭文件被瀏覽器自動填充最重要php force下載頭文件

例如,

header('Content-Description: File Transfer'); 
header('Content-type: application/zip'); 
header('Content-Length: '.sprintf("%u", filesize($zip_out))); 
header('Content-Transfer-Encoding: binary'); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header('Pragma: public'); 
header('Content-Disposition: attachment; filename="'.basename($zip_out).'"'); 

我省略了第1行和第2行以外的所有標題,下載工作正常,爲什麼/如何?

回答

3

Content-Disposition: attachment說您的瀏覽器的內容是附件。因此,瀏覽器將開始將內容作爲文件下載。

根據RFC 6266

如果部署類型「附件」(不區分大小寫), 匹配這表示收件人應提示用戶保存到本地 反應,而不是處理其通常(按其媒體 類型)。

Content-type: application/zip說,你的瀏覽器,內容是壓縮,通常使瀏覽器下載內容的文件時,即使省略Content-Disposition: attachment,因爲那是瀏覽器壓縮內容的默認行爲。

我從來沒有見過Content-Description頭中的任何HTTP相關規範,我認爲它不會影響下載。