How to upload Files with chinese names in PHP?

I have learning portal(LMS) where I will upload documents, images, videos etc to create content. If the file being uploaded has a chinese name then it is not getting uploaded. Instead a corrupted file with junk name is uploaded.

For example, I tried to upload a file named 地球科学.jpg. But on the server I got this file as 地çƒç§‘å­¦.jpg. Also the uploaded file is corrupted in the server.

I want this file to get upload with the same name on the server. Because I want to search for these files and reuse later for creating content.

FYI: I have XAMPP server installed on Windows XP. Chinese, Korean, and Japanese language packs installed.

Thanks for your answers.

AFAIK ntfs can't handle some characters on the filesystem. I would suggest to store the file with a generic name.

for example you could create a table with two columns: name and file, as name you save the original name, and as file you set something like md5(name).

how to: support chinese characters in file name · Issue #139 , see upload-process-form.php see line 444. includes/classes/file-upload.php see line 51 and 62. Could you give a specific example to what it  We’re going to create two PHP files: index.php and upload.php. The index.php file holds code which is responsible for displaying the file upload form. On the other hand, the upload.php file is responsible for uploading a file to the server. Also, a file will be uploaded in the uploaded_files directory,

If you need the name to search for it use a database to store name information and the file location and save the file using your own convention.


// sql entry 
original name = 地球科学.jpg
path = /some/place/1.jpg

When you search you use the db to locate a given file name and location. Separation storage logic is something common when building image storage solutions not only for naming problems but also for limitations/spped considerations in terms of the number of files that accumulate in folders.

Can't use post to upload a file with Chinese characters in its name , It seems PHP is also affected by this, if you try to upload a file to a server running PHP, with the name 'fårikål.txt', it will throw a warning: "PHP  If no file is selected for upload in your form, PHP will return $_FILES['userfile']['size'] as 0, and $_FILES['userfile']['tmp_name'] as none. The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.

Use iconv or mb_convert_encoding to change character string encoding.

// Upload the file into the temp dir
$target_path = "uploadfiles/"; 
$target_path .= $_FILES['fileField']['name']; 

// iconv()
move_uploaded_file($_FILES['fileField']['tmp_name'], iconv("UTF-8", "big5", $target_path))
// mb_convert_encoding()
move_uploaded_file($_FILES['fileField']['tmp_name'], mb_convert_encoding($target_path, "big5", "UTF-8"))

Unable to upload an image with non-ascii (Chinese) characters , I tried uploading an image with an English filename which went For files with Chinese names I still got the same error.​ProcessWire/blob/master/wire/core/WireUpload.php#L213. In this tutorial we will learn how to upload files on remote server using a Simple HTML form and PHP. You can upload any kind of file like images, videos, ZIP files, Microsoft Office documents, PDFs, as well as executables files and a wide range of other file types. Step 1: Creating an HTML form to upload the file. The following example will create a simple HTML form that can be used to upload files.

Make sure the page displaying the form is rendered in utf-8 or higher, usually this does the job, you can also choose to use the accept-charset attribute of the form element to indicate the posted data is sent as the specified charset.

Not sure if this all will do the job, let me know.

Upload File With Any Charset - General Discussion, German, Chinese etc) But the uploaded file has different name for and use that as lookup php is not really good at unicode encoding at the  The example from the PHP manual: basename() has a bug when processes Asian characters like Chinese. I would suggest pathinfo over basename as Metafaniel posted below. pathinfo() will give you an array with the parts of the path. Or for the case here, you can just specifically ask for the filename.

I think you might want to use somekind of database solution, especially when you need to search files later on. With database you can avoid I/O overhead.

Chinese filenames - PHP, I'm using PHP 5 and. Apache 2.2. When I attempt to upload a file with chinese filenames, the file name gets mutated into dashes, pretty much  Just copy the old contents (if necessary), and write the new contents into a new file, then rename over the original file.

move_uploaded_file - Manual, Check $_FILES[][name] * * @param (string) $filename - Uploaded file name. * @​author Yousef Ismaeil Cliprz */ function check_file_uploaded_name ($filename) This code uses the rand function to generate a random number as the file name. Another idea is to use the time function so that each file is named after its timestamp. The PHP then combines this name with the extension from the original file and assigns the subdirectory make sure this exists!

Handling file uploads - Manual, On this example, obtain safe unique name from its binary data. If you are going to do a file upload, I recommend you use the PHP FTP Functions in conjunction  When I failed to upload some files to server by IE, meanwhile some others can be uploaded. If I change the chinese names of the files to english names or some other chinese names , they can be uploaded. According to the log, the file names in the command STOR is wrong. (But the file names in the command DELE is right.)

CURLFile - Manual, name. Name of the file to be uploaded. mime. MIME type of the file (default is application/octet-stream). postname. The name of the file in the upload data 

  • Do you know how this file is being created on the server? Where is your PHP code for this?
  • I can confirm it is not your OS. I have the same OS and CJK stuff installed. It's probably your PHP script/env.
  • Have you tried it? I just did, and it works. 地球科学.jpg is a perfectly valid NTFS filename.
  • am currently not a win user. but could you confirm that its cross-platform-compatible? guess not. same problematic as a customer would upload a file named '--foobar.jpg' to a linux environment (ever tried to delete such a file? ;) )
  • Compatible with what platform? I ran it on WindowsXP x86. I don't what other platform WindowsXP runs on. I guess there is Windows for Itanium?
  • this solution worked, as suggested by Flask I created a table with 2 columns, name and file and then did all the processes required. Thanks Flask
  • I have changed all the pages in utf-8 but no success