使用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).'"');
|