IE 11 Download File Chinese garbled solution (go/php)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

IE 11 downloaded the file when found garbled.

Online Check the information, understand, mainly user-agent changed, is no longer msie, face is rv:11.0 so, as long as the service side to determine that is IE 11, processing with the same as MSIE.


GO:

func    setdownloadfilename   ( w  http.  Responsewriter   filename   agent  string  )    { 
  ifstrings. Contains(agent,"MSIE"){
 fileName=url. Queryescape(fileName)
 fileName=strings. Replace(fileName,"+","%20" ,  -1)
    }
      Span style= "font-weight:600; Color: #64b1ff ">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)) {& Lt;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" >&lt ;/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. '"' );}



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.