使用php header實現文件下載時,在IE6下總是提示不能下載,谷歌浏覽器正常, 因此應該是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).'"');