IE 11下载文件中文乱码解决(go/php)
来源:互联网 发布:net高级编程 编辑:程序博客网 时间:2024/04/30 02:23
IE 11下载文件的时候发现乱码.
网上查了下资料,了解了一下,主要是user-agent变了,不再是MSIE,面是rv:11.0这样,所以只要服务端判断出是IE 11,处理跟MSIE一样。
GO:
func setDownloadFileName(w http.ResponseWriter, fileName, agent string) {
if strings.Contains(agent, "MSIE") {
fileName = url.QueryEscape(fileName)
fileName = strings.Replace(fileName, "+", "%20", -1)
}
if strings.Contains(agent, "rv:") && strings.Contains(agent, "Gecko") {
fileName = url.QueryEscape(fileName)
fileName = strings.Replace(fileName, "+", "%20", -1)
}
w.Header().Set("Content-Disposition", "attachment;filename=\""+fileName+"\"")
}
PHP:
$ua = isset ( $_SERVER ["HTTP_USER_AGENT"] ) ? $_SERVER ["HTTP_USER_AGENT"] : '';<span style="white-space:pre"></span>if (preg_match ( "/MSIE/", $ua )) {<span style="white-space:pre"></span>$file_name = rawurlencode ( $file_name );<span style="white-space:pre"></span>header ( 'Content-Disposition: attachment; filename="' . $file_name . '"' );} else if (preg_match ( "/Firefox/", $ua )) {<span style="white-space:pre"></span>header ( 'Content-Disposition: attachment; filename*="utf8\'\'' . $file_name . '"' );} elseif (stripos ( $ua, 'rv:' ) > 0 && stripos ( $ua, 'Gecko' ) > 0) {<span style="white-space:pre"></span>$file_name = rawurlencode ( $file_name );<span style="white-space:pre"></span>header ( 'Content-Disposition: attachment; filename="' . $file_name . '"' );} else {<span style="white-space:pre"></span>header ( 'Content-Disposition: attachment; filename="' . $file_name . '"' );}
0 0
- IE 11下载文件中文乱码解决(go/php)
- 解决php 文件下载 IE 文件名中文乱码
- 解决PHP在IE浏览器下载文件,中文文件名乱码问题
- IE 11 解决下载文件名中文乱码的问题
- IE下载时中文文件名乱码解决
- 文件下载解决中文乱码
- 文件下载中文乱码解决
- IE文件下载时中文文件名乱码
- 解决PHP下载文件名中文解决乱码
- IE 下 js文件 中文乱码解决
- 在ie浏览器下载文件乱码解决
- php文件下载IE文件名乱码问题
- 解决springmvc返回json数据IE出现文件下载和json数据中文乱码问题
- 解决Java下载文件,文件名包含中文在IE浏览器乱码问题
- 解决PHP下载文件名中文乱码
- IE下载乱码解决
- 解决Tomcat下载中文名字文件乱码
- Struts1.2文件下载(解决中文乱码)
- 批量发工资或发邮件
- LeetCode----树
- python学习笔记(三)
- .NET开发需要养成一种良好的注释代码习惯篇
- IP101A芯片默认物理地址(PHY Adress)确定
- IE 11下载文件中文乱码解决(go/php)
- poj Wormholes (最短路 spfa Bellman-Ford 算法 邻接表实现)
- 添加对象到对象仓库的三种方法
- Windows QT环境配置
- 写代码,是一件幸福的事儿
- 网口扫盲一:网卡初步认识
- liunx环境下安装redis
- php-fpm自启动脚本
- LeetCode123:Best Time to Buy and Sell Stock III