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数组实例总结与说明

如果您有很大的一个数组,而所要完成的仅是找出一个存在的给定值,您可以使用in_array()以返回true或false。如下代码将输出“Not found in this array”,...

PHP filesize函数用法浅析

filesize() 函数返回指定文件的大小。 若成功,则返回文件大小的字节数。若失败,则返回 false 并生成一条 E_WARNING 级的错误。 php filesize()函数...

php绘图之在图片上写中文和英文的方法

本文实例讲述了php绘图之在图片上写中文和英文的方法。分享给大家供大家参考。具体如下: 第一种方法,只能写英文,中文会出现乱码 复制代码 代码如下:<?php //1、创建...

PHP基于Redis消息队列实现发布微博的方法

PHP基于Redis消息队列实现发布微博的方法

本文实例讲述了PHP基于Redis消息队列实现发布微博的方法。分享给大家供大家参考,具体如下: phpRedisAdmin :github地址  图形化管理界面 git c...

PHP中HTML标签过滤技巧

在开发文章系统中正常需要用到HTML标签、JS脚本等其他脚本代码的过滤,稍微尝试了下,感觉简单的htmlspecialchars()函数的过滤效果始终不如strip_tags()函数的过...