Internet Explorer 11 downloads garbled Chinese characters to solve go/php

Source: Internet
Author: User
: This article describes how to solve the problem of garbled Chinese characters in the downloaded files of IE11. if you are interested in the PHP Tutorial, refer to it. IE 11 found garbled characters when downloading files.

After checking the information on the Internet, I learned that the user-agent has changed. it is no longer MSIE, and the plane is rv: 11.0. Therefore, as long as the server determines that it is IE 11, same as 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 . '"' );}

The above describes how to solve the go/php problem by downloading files in IE 11 in Chinese, including some content. I hope my friends who are interested in the PHP Tutorial can help me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.