Phpmove_uploaded_file: Chinese Garbled text or upload failure-PHP source code

Source: Internet
Author: User
Ec (2); php is made by foreigners. It is not perfect in some aspects of Chinese support, so we found that Chinese uploading was not successful, let's take a look at the instance and solution. * $ Filepathupfile; if ($ _ FILES [file] [error] 0) {& nbsp; if (move_uploaded_file ($ _ FILES [fi script ec (2); script

Php is made by foreigners. It is not perfect in some aspects of Chinese support, so we can find that Chinese uploading fails,
Let's take a look at the instance and solution.
*/
$ Filepath = 'upfile /';

If ($ _ FILES ['file'] ['error'] = 0)
{

If (move_uploaded_file ($ _ FILES ['file'] ['tmp _ name'], $ filepath. $ _ FILES ['file'] ['name'])
{
Echo 'file uploaded successfully ';
}
Else
{
Echo 'file Upload Failed ';
}
}


/*
.....
The above is a simple file upload code. It is okay to transfer the English language, but the Chinese language won't succeed. Well, how can we deal with the problem of failed uploading of Chinese file names.
The simple method is to rename the uploaded file name and then click OK. Next we will modify the program. As follows.
*/

If ($ _ FILES ['file'] ['error'] = 0 ){

$ Ext = end (explode ('.', $ _ FILES ['file'] ['name']);
$ FileRandName = time (); // generate a string based on the current time

If (move_uploaded_file ($ _ FILES ['file'] ['tmp _ name'], $ filepath. $ fileRandName. '.'. $ ext ))
{
Echo 'file uploaded successfully ';
}
Else
{
Echo 'file Upload Failed ';
}
}

// No matter what file you upload, it is OK.
// The original article on this site is reprinted to indicate that it is from www.111cn.net

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.