Solve the problem of PHP uploading files in IE with garbled file names

Source: Internet
Author: User
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 );






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.