PHP IE中下载附件问题解决方法

yipeiwu_com6年前PHP代码库
重点:

1、在IE中下载附件之前要清空缓存。

2、中文文件名要用urlencode编码。
复制代码 代码如下:

Header("Pragma: "); //不加的话,IE中会提示目标主机无法访问
Header("Cache-Control: "); //不加的话,IE中会提示目标主机无法访问
Header("content-type: $type");
Header("accept-ranges: bytes");
Header("Content-Transfer-Encoding:base64");
Header("accept-length: " . filesize($path_c));
Header("content-disposition: attachment; filename=" .urlencode($filename)); //IE中不用urlencode中文名会出现乱码
readfile($path_c);
exit;


复制代码 代码如下:

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.urlencode(basename($file) )); //IE中不用urlencode中文名会出现乱码
header('Content-Transfer-Encoding: binary'); //二进制传输
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); //不加的话,IE中会提示目标主机无法访问
header('Pragma: public'); //不加的话,IE中会提示目标主机无法访问
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;

相关文章

php实现Session存储到Redis

对于大访问量的站点使用默认的Session 并不合适,我们可以将其存入数据库、或者使用Redis KEY-VALUE数据存储方案 首先新建一个session表 CREATE TAB...

PHP详解ASCII码对照表与字符转换

PHP详解ASCII码对照表与字符转换

一,通用的ASCII码对照表 图解ASCII码对照表图,以字符A为例Dec表示十进制,如65Hx表示十六进制,如41Oct表示八进制,如101Char表示显示字符,如AASCII码对...

web站点获取用户IP的安全方法 HTTP_X_FORWARDED_FOR检验

安全过滤后的getIP函数 复制代码 代码如下:  function getIP() { $realip = ''; //设置默认值 if (isset($...

php中利用explode函数分割字符串到数组

分割字符串 //利用 explode 函数分割字符串到数组 复制代码 代码如下: <?php $source = "hello1,hello2,hello3,hello4,hell...

php处理json时中文问题的解决方法

操作的代码如下: 复制代码 代码如下: <?php $usr = new User(); echo json_encode($usr); ?> 很简单的代码,无中文情况一切...