Jump to content

Unable to upload an image with non-ascii (Chinese) characters

Recommended Posts

I tried uploading an image with an English filename which went through perfectly fine. Then I copied and pasted the same exact file and gave it a Chinese name instead. Next I attemped to upload this image however I got this error message:

"Unable to move uploaded file ..."

I am not sure how to solve this problem. Any help would be greatly appreciated!

Link to post
Share on other sites

Hi there !

The forum of processwire has more than 4 years of posts and has become a great source of information.

Your answer is already in there. Did you have a look ?

Welcome to processwire and why not tell us something more and introduce your self.

Link to post
Share on other sites

This is made by design to avoid problems with handling files on wide range of server OCs. At least, this is how I inderstand it. You can solve the problem by renaming files on upload with this Adrian's module. Have not tried it myself, so please report back if you choose to go this way ))

Actually I would like to read more about this myself, if someone could share some links.

  • Like 2
Link to post
Share on other sites

Hello Ivan thanks for your help. I actually tried that module before posting this thread. Unfortunately it did not work for me. For files with English names it worked like a charm. However that is not my problem here. For files with Chinese names I still got the same error. 

And hello Pwired (and anyone else). I am the owner of a small web development firm here in China. However I studied in the U.S. for the last five years so I am exposed a lot to all these 'foreign technologies' and we used these tech exclusively to differentiate ourselves. My company is currently using CouchCMS to develop sites for clients. However I am looking for another more extensible alternative and I found Processwire. I just have to make sure that it will work properly for my clients. 

Link to post
Share on other sites

Update: If the image's filename contains ONLY Chinese characters I got the same error as before. However, if it has any ascii character in it (eg: numbers, letters, punctuation), for example: “未命名-1.jpg”, the module will kick in and rename the uploaded file name for me. Could anyone explain this phenomenon to me? 

Thank you very much.


  • Like 1
Link to post
Share on other sites

Just guessing: the module renames only those characters it is aware of. So "未命名-1.jpg" gets renames to something like "____-1.jpg" and if there is no other files whick got renamed to same kind of nonsense name there would be no filename conflict. So you can upload "未命名-2.jpg" to the same field, but not "名未命-1.jpg".

Probably there is a way to include some transliteration table/array for simlified chinese to the module, but Adrian has to step in here (as I may be wrong about all this).

Link to post
Share on other sites

Hi guys,

A quick guess here - I think PW itself is likely stripping all the non latin characters from the filename as the first step. So if there are no latin characters at all, there is nothing left and so the file is rejected. If there is at least one latin character then it can continue to the point where my module hooks in and sets the new filename.

I think these are the two relevant spots in the PW core:



Not really sure what can be done about this at the moment. Here is one other relevant post:


  • Like 1
Link to post
Share on other sites

Please help me on this!

I followed your links, Adrian, and it seems like in validateFilename function there is already a possibility to get the transliterated name for a file by passing "TRUE" instead of "Sanitizer::translate" to filename method.

$value = $this->wire('sanitizer')->filename($value, Sanitizer::translate); 

I am so unexperienced in this, that I may be completely wrong. And if I am not, I still do not know how to hook and change that constant.

But if there is a way to transliterate a name for a page there must be a way to transliterate a filename. We just need to find out how )))

Link to post
Share on other sites

Actually I was just working on filename cleaning for Migrator and learned a little more :)

I played around with sanitizer->filename and didn't achieve what I wanted, so I ended up making use of:


public function cleanBasename($basename, $originalize = false, $allowDots = true, $translate = false)

Does that translate option help for you guys?

This is where it is used during Pagefile::install (which is when a file is added to the system)


Notice that it is set to true here, even though the default for the function is false.

  • Like 1
Link to post
Share on other sites

Hello Adrian. Thanks for your answer! However I'm still not quite sure what you were suggesting.. Could you please elaborate a little bit more? I looked into that cleanBasename function and sort of understand what it does / what its purpose is. I'm pretty sure you are not suggesting that I should modify this core function right?

Thank you very much.

Link to post
Share on other sites

Sorry - no I am not suggesting you modify the core - it was just meant to be some info to show where the sanitizing of the name is occurring.

I just tested an image upload that I named: 名未命.png and it worked perfectly with Custom Upload Names installed - it was renamed to exactly what the rule specified. Without it installed it still uploaded but got renamed to png.png which is a bit weird, but it still worked.

What version of PW are you running. I am running latest dev. Does it make a difference for you if you upgrade?

  • Like 1
Link to post
Share on other sites

I am actually running the latest stable version that I downloaded a few days ago, which I believe is 2.5.2. After a fresh installation I am still getting this error: 

名未命.png - Unable to move uploaded file to: /var/www/..........

Maybe I should try the latest dev version as well however I don't think that's gonna make a difference though...

Do you guys have any idea regarding to why this is happening to share with me? I would really appreciate any inputs!

Link to post
Share on other sites

It seems like it might be server specific. I just tried again on my local dev setup and it works as I reported in my last post. But then I just tried via lightning.pw and it failed with the same message you are getting.

I honestly don't know why though. Do you have another environment you might be able to test with?

Link to post
Share on other sites

I tried another hosting but unfortunately I am getting the same error. I might need to fall back to Perch CMS for this upcoming project then, which I think does less for more (although it's indeed easier than Processwire to set up in my opinion). I will come back and dig a little bit more into this issue in the future. Thanks for all your help! And please keep me posted if any solution is found :)

Link to post
Share on other sites

It seems like it might be server specific. I just tried again on my local dev setup and it works as I reported in my last post. But then I just tried via lightning.pw and it failed with the same message you are getting.

Thakns for the Info. We might also have to look into this issue. Maybe our server admin can figure it out and then we can report back.

  • Like 2
Link to post
Share on other sites


So I ended up modifying the core to cope with this... (yeah I know this is not a good idea but I need this to be functional for my Chinese clients)

In WireUpload.php line 240 I added:

$filename = 'file-' . $filename;


$filename = $this->getTargetFilename($filename);

$filename = $this->validateFilename($filename);

This will force every file uploaded to start with a 'file-' prefix so that the system will not have files with a filename consisting Chinese characters only.

However I ran into another problem:

If I upload 'test.jpg', I get 'file-test.jpg' which is good.

But if I upload '未命名.jpg', I get 'file-' instead, missing the extension.

Then, if I upload '未命名.jpg' again, I get 'file--1.' again missing the extension but with a trailing dot...

This inconsistency is really just weird to me. For English filenames I got the extension, for the first Chinese filename I got the filename without the extension. And if I upload another file of Chinese filename, I got the filename and the dot (e.g.:  file--1. )

Despite all this, I can still view these files as images in my browser, so ...../file-test.jpg , ...../file- ,  ........../file--1. all display the image without any error.

If I insist I need to modify the core in order to make this work (before any official fix is available). Where is the best place to do so? The way I did it works in some sense but produces all these weird filenames which are not really desirable.

Anyone familiar with the core willing to help out here? Thank you so much in advance!

  • Like 1
Link to post
Share on other sites

I just played with uploading your files and it worked fine (maybe not so fine, but worked) for me without Adrians module on PW 2.4.14. Got the same results as Adrian. Maybe png.png is not the best option and should be changed, but it does function. I tried moving around those hieroglyphs so I get two 3-symbol files with untranslatable symbols in the filename and it still worked. I got  "png.png" and "png-1.png" or something like that.

Working on Windows 7 with XAMPP.

Link to post
Share on other sites
  • 5 months later...

This issue still exists on (at least my) linux servers. If a file to upload does not contain any latin characters, you get the "Unable to move uploaded file to: ..." error. If a file name has at least any latin character, the upload works. On windows everything works fine. Can we do something about it?

  • Like 1
Link to post
Share on other sites
  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By prestoav
      Hi there, I'm hoping someone can help here.
      I've just moved a new site from my development server account over (where the site was working fine for the client to edit content pre-launch) to the client's final hosting account and the live site is all fine. However, while most edits can be done without an issue, image uploads in admin cannot. I know this has been an issue before but, having trawled the posts about it and suggested esolutions I still can't resolve it on their host.

      PW Version: 3.0.123
      PHP version: 7.3.20
      max_execution_time 160
      max_upload_size 256M
      GD Library is enabled

      Looking at the console data it looks like the AJAX request from the image upload is getting a 403 error which is suggesting a permissions issue? First we get this on console:
      ?id=1169&s=1&c=1:1 Uncaught SyntaxError: Unexpected token < in JSON at position 0 Then, the AJAX request:
      https://*******/admin/page/edit/?&id=1169&InputfieldFileAjax=1 Gets a 403 according to Chrome Dev Tools > Network XHR. Also, the response is empty.

      Can anyone point me in the direction of the directory that deals with this and what the permission should be to allow it or indeed any other fix / area to investigate?

      Thanks so much for your help.

    • By Xonox
      I'm trying to upload images from a folder into a page. I need to replace the images instead of adding. The image field already has the replace existing images turned on, but it doesn't seem to be enough.
      My code:
      foreach($files as $file) { if(substr($file, 0, 1) != '.' && $file != '.' && $file != '..') { // Get SKU $file_sku = substr($file, 0, 9); // Check for book $book = $pages->get('sku=' . $file_sku); if(!$book->id) { // Book doesn't exist } else { // Upload image into book !!! THIS CODE ADDS FILE INSTEAD OF REPLACING. HOW CAN I REPLACE? $book->book_images->add($upload_directory . '/' . $file); // Delete file unlink($upload_directory . '/' . $file); } // Save book if($book->id) $book->save(); } }  
      What am I missing?
    • By Guy Incognito
      I'm trying to implement a front-end image upload form for user profile pictures, to a field called 'profile_picture'. The code is based on the various examples found around these forums but isn't yet 100% right.
      The form successfully submits the image to the server and updates the field in the dashboard. When you submit the firm, the page reloads and uploads the image but the template still loads the old image path (now broken path as the old image has been removed).
      I can only get the new image to show if I hit enter in the address bar forcing the page to reload.
      Any ideas? Is it a caching issue, or something to do with the order of the script? It makes no difference if I call the image after the upload form.
      <?php //Display current user image $userImg = $user->profile_picture->first(); echo '<img src="'.$userImg->url.'">'; $upload_path = $config->paths->assets . "files/avatar_uploads/"; $f = new WireUpload('userimage'); $f->setMaxFiles(1); $f->setMaxFileSize(1*1024*1024); $f->setOverwrite(true); $f->setDestinationPath($upload_path); $f->setValidExtensions(array('jpg', 'jpeg', 'png', 'gif')); if($input->post->form_submit) { if(!is_dir($upload_path)) { if(!wireMkdir($upload_path)) throw new WireException("No upload path!"); } $files = $f->execute(); if ($f->getErrors()) { foreach($files as $filename) @unlink($upload_path . $filename); foreach($f->getErrors() as $e) echo $e; } else { $user->of(false); $user->profile_picture->removeAll(); // wirearray (line added by @horst: explanation is three posts beneath) $user->profile_picture = $upload_path . $files[0]; $user->save(); $user->of(true); @unlink($upload_path . $files[0]); } } ?> <form class="forum-form" accept-charset="utf-8" action="./" method="post" enctype="multipart/form-data" > <input type="file" id="attach" name="userimage" accept="image/jpg,image/jpeg,image/gif,image/png" /> <input type="submit" name="form_submit" value="Submit"/> </form>
    • By bot19
      Hey guys,
      Today I was uploading images and ran into an image I couldn't upload. This has never happened before since I got images uploading working.
      I had a dig around the forum but couldn't find anything relevant.
      Initially I thought it was due to the size ~1.3mb, but I had uploaded something bigger after and it was fine (~1.7mb). There are no size or dimension restrictions on this image field.
      After looking at the image some more, I realised its dimensions was HUGE: ~5300px
      There must be some sort of limit somewhere throwing an error due to this dimension size? Because after I resized the image down to 2560px, it uploaded fine.
      What does everyone think? I kind of just want to know. See below for more info. Thanks!
      Uploading the smaller file, everything is fine. If you look at the response, you can see:
      [{"error":false,"message":"Added file: mock-email-marketing-and-newsletters-smaller.png","file":"\/procwire\/site\/assets\/files\/1189\/mock-email-marketing-and-newsletters-smaller.png","size":340797,"markup":"<li id='file_551ac1043f1cbbe0b909dab963a1f28c' class='ImageOuter gridImage ui-widget'><div class='gridImage__tooltip'><table><tr><th>Dimensions<\/th><td>2560x2560<\/td><\/tr><tr><th>Filesize<\/th><td>333&nbsp;kB<\/td><\/tr><tr><th>Variations<\/th><td>0<\/td><\/tr><\/table><\/div>\n\t\t\t<div class='gridImage__overflow'>\n\t\t\t\t<img src=\"\/procwire\/site\/assets\/files\/1189\/mock-email-marketing-and-newsletters-smaller.0x260.png?nc=1512803364\" alt=\"\" data-w=\"2560\" data-h=\"2560\" data-original=\"\/procwire\/site\/assets\/files\/1189\/mock-email-marketing-and-newsletters-smaller.png?nc=10\" \/>\n\t\t\t<\/div>\n\t\t\t\n\t\t\t\t<div class='gridImage__hover'>\n\t\t\t\t\t<div class='gridImage__inner'>\n\t\t\t\t\t\t<label for='' class='gridImage__trash'>\n\t\t\t\t\t\t\t<input class='gridImage__deletebox' type='checkbox' name='delete_crm_feature_img_repeater1189_551ac1043f1cbbe0b909dab963a1f28c' value='1' title='Delete' \/>\n\t\t\t\t\t\t\t<span class='fa fa-trash-o'><\/span>\n\t\t\t\t\t\t<\/label>\n\t\t\t\t\t\t<a class='gridImage__edit'>\n\t\t\t\t\t\t\t<span>Edit<\/span>\n\t\t\t\t\t\t<\/a>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\t\t\t\t<div class='ImageData'>\n\t\t\t\t\t<h2 class='InputfieldImageEdit__name'><span contenteditable='true'>mock-email-marketing-and-newsletters-smaller<\/span>.png<\/h2>\n\t\t\t\t\t<span class='InputfieldImageEdit__info'>333&nbsp;kB, 2560&times;2560 <\/span>\n\t\t\t\t\t<div class='InputfieldImageEdit__errors'><\/div>\n\t\t\t\t\t<div class='InputfieldImageEdit__buttons'><small><button type='button' data-href='\/procwire\/admin123\/page\/image\/edit\/?id=1189&file=1189,mock-email-marketing-and-newsletters-smaller.png&rte=0&field=crm_feature_img' class='InputfieldImageButtonCrop ui-button ui-corner-all ui-state-default pw-modal-large pw-modal' data-buttons='#non_rte_dialog_buttons button' data-autoclose='1' data-close='#non_rte_cancel'><span class='ui-button-text'><span class='fa fa-crop'><\/span> Crop<\/span><\/button><button type='button' data-href='\/procwire\/admin123\/page\/image\/variations\/?id=1189&file=mock-email-marketing-and-newsletters-smaller.png&modal=1&varcnt=varcnt_crm_feature_img_repeater1189_551ac1043f1cbbe0b909dab963a1f28c' class='ui-button ui-corner-all ui-state-default pw-modal-large pw-modal' data-buttons='button'><span class='ui-button-text'><span class='fa fa-files-o'><\/span> Variations <span class='ui-priority-secondary'>(0)<\/span><\/span><\/button><\/small><\/div>\n\t\t\t\t\t<div class='InputfieldImageEdit__core'><div class='InputfieldFileDescription'><label for='description_crm_feature_img_repeater1189_551ac1043f1cbbe0b909dab963a1f28c' class='detail'>Description<\/label><input type='text' name='description_crm_feature_img_repeater1189_551ac1043f1cbbe0b909dab963a1f28c' id='description_crm_feature_img_repeater1189_551ac1043f1cbbe0b909dab963a1f28c' value='' \/><\/div><\/div>\n\t\t\t\t\t<div class='InputfieldImageEdit__additional'><\/div>\n\t\t\t\t\t<input class='InputfieldFileSort' type='text' name='sort_crm_feature_img_repeater1189_551ac1043f1cbbe0b909dab963a1f28c' value='2' \/>\n\t\t\t\t\t<input class='InputfieldFileReplace' type='hidden' name='replace_crm_feature_img_repeater1189_551ac1043f1cbbe0b909dab963a1f28c' \/>\n\t\t\t\t\t<input class='InputfieldFileRename' type='hidden' name='rename_crm_feature_img_repeater1189_551ac1043f1cbbe0b909dab963a1f28c' \/>\n\t\t\t\t<\/div>\n\t\t\t<\/li>","replace":true,"overwrite":0}]
      Uploading the original file, something happens and there is no response (see Content-Length: 0)

      Which in turn must trigger this issue in the JS.

      No response.

  • Create New...