Wamp environment UTF8 Code upload Chinese name file filename garbled

Source: Internet
Author: User

Test environment:

Windows7 php5.5.12 apache2.4.9


Form form

<form action= "HTTP://127.0.0.1/" method= "post" enctype= "Multipart/form-data" > <input type= "file" Name= "Max_ File_size "value=" 1000000 "/> <input type=" Submit "name=" Submit "></form>


PHP Processing Code

if ($_server["request_method"] = = "POST") {var_dump ($_files); $info = PathInfo ($_files["max_file_size" [' name ']); move _uploaded_file ($_files["max_file_size" [' Tmp_name '], ' fx\\ '. $_files["max_file_size" [' name ']); exit ();

Test One:

1, Form form file and PHP file are UTF8 encoded

2, select the Chinese name file submission upload, output $_files array, file name display normal

3, the server disk file name is garbled, the file content is normal

Test Two:

1. Change Form form page encoding to GBK PHP processing page code is UTF8

2, choose the Chinese name file upload, output $_files array, file name garbled

3, the server disk file name is normal, the file content is normal


Conclusion:

Because there is only a window server environment, so for the time being in the window environment summarized as the server in the processing of file uploads, regardless of what the page encoding, perhaps because it is a Windows Server reason, read the uploaded file name always use GBK encoding , So when the submission page is not submitted by GBK encoding, it will be garbled. The workarounds are:

1, the protection of the submission page encoding and processing page encoding consistent, will not cause the processing page to get the information garbled

2, the submission page encoding for GBK will not cause the Chinese name uploaded to the server file name garbled

3, if the submission page is not GBK encoding, the processing page when writing to the file, the filename should be converted to GBK encoding Iconv ("Submit page encoding", "GBK", file name)

4, because the test environment is only Windows Server, so the reason for garbled is due to the server read the file name encoding format causes the non-GBK submitted page file name garbled, if you have other test environment, trouble to help test thank you.

Wamp environment UTF8 Code upload Chinese name file filename garbled

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.