使用php header實現檔案下載時,在IE6下總是提示不能下載,Google瀏覽器正常, 因此應該是IE的問題,IE下有個bug,微軟官網有說明。錯誤訊息:“Internet Explorer cannot download a file”(Internet Explorer 不能下載檔案),有個辦法可以很好的解決,
看代碼好了:
下面整理了一個函數
| 代碼如下 |
複製代碼 |
if(strstr($_SERVER["HTTP_USER_AGENT"],"MSIE")==false) { header("Cache-Control: no-cache"); header("Pragma: no-cache"); } header('Cache-Control: public, must-revalidate, max-age=0'); header('Accept-Ranges: bytes'); header("Content-Type: application/force-download"); header("Content-Type: application/download"); header("Content-Type: application/octet-stream"); if(!empty($content_type)){ header("Content-Type: ".$content_type); } header("Content-Transfer-Encoding: binary"); header('Content-Disposition:attachment;filename="'.rawurlencode($filename).'"'); |
http://www.bkjia.com/PHPjc/632115.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632115.htmlTechArticle使用php header實現檔案下載時,在IE6下總是提示不能下載,Google瀏覽器正常, 因此應該是IE的問題,IE下有個bug,微軟官網有說明。錯誤訊息...