To solve the problem of PHP downloading files in IE and garbled file names, you can use the following code to export the files as streams instead of opening the file header ("Content-Type: application/force-download; charset = utf-8; name = \ "$ file_name \"); header ("solves the problem of PHP downloading files in IE and garbled file names
You can use the following code to export the file as a stream instead of opening the file.
Header ("Content-Type: application/force-download; charset = utf-8; name = \" $ file_name \ "); header (" Content-Transfer-Encoding: binary "); header (" Content-Disposition: attachment; filename = \ "$ file_name \"");
However, if your file_nameis 8 bytes, for example, the file name is test .html;
In this case, the file name becomes garbled.
In RFC2231, the Content-Disposition of multi-language encoding should be defined as follows:
Content-Disposition: attachment; filename * = "utf8'%e6%b5%8b%e8%af%95.html"
That is:
Add the equal sign after filename *
The filename value is divided into three sections by single quotes, which are character set (utf8), Language (null), and URL code file names.
Therefore, url encoding should be performed on the file name. using php's urlencode can be easily completed.
Therefore, the above code should be added with url encoding conversion
$ File_name = urlencode ($ file_name );