Php utf8 encoding garbled characters in the uploaded Chinese file name

Source: Internet
Author: User

Below I will summarize the php utf8 encoding to upload a Chinese file name garbled solution. If you have such problems, please refer.

The Code is as follows: Copy code

<? Php
If (isset ($ _ FILES ['file']) {
$ Upload = 'upload/'. $ _ FILES ['file'] ['name'];

If (is_uploaded_file ($ _ FILES ['file'] ['tmp _ name']) {

// The iconv function solves the problem of garbled Chinese names of uploaded files, but it does not advocate that the file names are Chinese characters, especially in unix/linux environments. When you want to output the files, you need to change them back, iconv ('gb2312', UTF-8 ', $ upload)

If (! Move_uploaded_file ($ _ FILES ['file'] ['tmp _ name'], iconv ('utf-8', 'gb2312', $ upload ))){

Echo 'failed ';

} Else {
Echo 'success ';

}
}
Else {
Echo 'failed ';

}

}
?>

/***** Application of iconv functions: string iconv (string in_charset, string out_charset, string str)
* In_charset: Format of the input file

* Out_charset: Format of the output file

* Str: file path

*****/

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.