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