Home > Backend Development > PHP Tutorial > IE 11 download file Chinese garbled solution go/php

IE 11 download file Chinese garbled solution go/php

WBOY
Release: 2016-08-08 09:22:42
Original
1117 people have browsed it

When IE 11 downloads files, I find garbled characters.

I checked the information online and found out that the main reason is that the user-agent has changed. It is no longer MSIE, but rv:11.0, so as long as the server determines that it is IE 11. The processing is the same as MSIE.

GO:

<span>func</span><span></span><span>setDownloadFileName</span><span>(</span>w<span></span>http<span>.</span>ResponseWriter<span>,</span><span></span>fileName<span>,</span><span></span>agent<span></span><span>string</span><span>)</span><span></span><span>{</span>
Copy after login
<span>    </span><span>if</span><span></span>strings<span>.</span>Contains<span>(</span>agent<span>,</span><span></span><span>"MSIE"</span><span>)</span><span></span><span>{</span>
Copy after login
<span>        </span>fileName<span></span><span>=</span><span></span>url<span>.</span>QueryEscape<span>(</span>fileName<span>)</span>
Copy after login
Copy after login
<span>        </span>fileName<span></span><span>=</span><span></span>strings<span>.</span>Replace<span>(</span>fileName<span>,</span><span></span><span>"+"</span><span>,</span><span></span><span>"%20"</span><span>,</span><span></span><span>-</span><span>1</span><span>)</span>
Copy after login
Copy after login
<span>    </span><span>}</span>
Copy after login
Copy after login
Copy after login
Copy after login
<span>    </span><span>if</span><span></span>strings<span>.</span>Contains<span>(</span>agent<span>,</span><span></span><span>"rv:"</span><span>)</span><span></span><span>&&</span><span></span>strings<span>.</span>Contains<span>(</span>agent<span>,</span><span></span><span>"Gecko"</span><span>)</span><span></span><span>{</span>
Copy after login
<span>        </span>fileName<span></span><span>=</span><span></span>url<span>.</span>QueryEscape<span>(</span>fileName<span>)</span>
Copy after login
Copy after login
<span>        </span>fileName<span></span><span>=</span><span></span>strings<span>.</span>Replace<span>(</span>fileName<span>,</span><span></span><span>"+"</span><span>,</span><span></span><span>"%20"</span><span>,</span><span></span><span>-</span><span>1</span><span>)</span>
Copy after login
Copy after login
<span>    </span><span>}</span>
Copy after login
Copy after login
Copy after login
Copy after login
<span>    </span>w<span>.</span>Header<span>().</span>Set<span>(</span><span>"Content-Disposition"</span><span>,</span><span></span><span>"attachment;filename=\""</span><span>+</span>fileName<span>+</span><span>"\""</span><span>)</span>
Copy after login

PHP:

<span>}</span>
Copy after login

The above introduces how to resolve Chinese garbled files downloaded by IE 11 in go/php, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template