当前位置:Gxlcms > PHP教程 > IE11下载文件中文乱码解决go/php

IE11下载文件中文乱码解决go/php

时间:2021-07-01 10:21:17 帮助过:19人阅读

IE 11下载文件的时候发现乱码.

网上查了下资料,了解了一下,主要是user-agent变了,不再是MSIE,面是rv:11.0这样,所以只要服务端判断出是IE 11,处理跟MSIE一样。

GO:

funcsetDownloadFileName(whttp.ResponseWriter,fileName,agentstring){
    ifstrings.Contains(agent,"MSIE"){
        fileName=url.QueryEscape(fileName)
        fileName=strings.Replace(fileName,"+","%20",-1)
    }
    ifstrings.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"] : '';
		
if (preg_match ( "/MSIE/", $ua )) {
	$file_name = rawurlencode ( $file_name );
	header ( 'Content-Disposition: attachment; filename="' . $file_name . '"' );
} else if (preg_match ( "/Firefox/", $ua )) {
	header ( 'Content-Disposition: attachment; filename*="utf8\'\'' . $file_name . '"' );
} elseif (stripos ( $ua, 'rv:' ) > 0 && stripos ( $ua, 'Gecko' ) > 0) {
	$file_name = rawurlencode ( $file_name );
	header ( 'Content-Disposition: attachment; filename="' . $file_name . '"' );
} else {
	header ( 'Content-Disposition: attachment; filename="' . $file_name . '"' );
}

以上就介绍了IE 11下载文件中文乱码解决go/php,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

人气教程排行