Home  >  Article  >  Backend Development  >  How to solve the problem of garbled download code in PHP IE

How to solve the problem of garbled download code in PHP IE

藏色散人
藏色散人Original
2020-08-28 09:08:361966browse

php IE download garbled solution: first open the corresponding PHP file; then when the file name is output, convert the file name into gb2312 encoding, code such as "$name = iconv("utf-8", "gb2312",$name);".

How to solve the problem of garbled download code in PHP IE

Recommendation: "PHP Video Tutorial"

During website development, download files are often encountered function, certain requirements require the download file name to be in Chinese.

Generally, UTF-8 encoding is used when outputting Chinese, but some versions of IE browser do not use UTF-8 encoding when converting downloaded file names, resulting in garbled file names. The file download function named "Chinese.txt" was tested. The download in IE 11 browser is as follows:


On other browsers, such as chrome, Firefox and 360 have no problem:


#I tried it and converted the file name into gb2312 encoding when the file name was output. The problem was solved. The code is as follows :

$name = '中文.txt';
//转换文件名编码
$name = iconv("utf-8","gb2312",$name);
Header("Content-Disposition: attachment; filename=".$name);

The screenshot of the effect is as follows:



The above is the detailed content of How to solve the problem of garbled download code in PHP IE. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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