• Hi,

    Hope it’s the right place to open a bug report.

    I tried to use the plugin to replace media with filename starting with Hebrew character (filename was in format “word1-word2.png” in Hebrew characters) and it didn’t succeed well (got 404). After a little digging I found out that the file is uploaded to the new name “-word2.png” (missing first chars with UTF-8 encoding). I found this post about basename and UTF-8. after adding setlocale(LC_ALL,’C.UTF-8′) to upload.php it worked OK.

    I’m pretty new to WP and php and I’m not sure whether its good idea to push it everywhere but mb it’s better to at least check if the filename include UTF-8 chars and add warning so people won’t get 404.

    Thanks!

    • This topic was modified 6 years, 7 months ago by nirroz.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter nirroz

    (@nirroz)

    After a little thinking I decided that I’m not feeling comfortable messing with the locale (and you probably won’t use it) so I just used something like here and changed line 216 in upload.php from:
    $current_filename = basename($current_file);
    to the following lines (with comment):
    // I added a after every / cause basename doesn’t deal with UTF-8 names good, then // substr with offset 1
    $current_file_add_a = str_replace(‘/’, ‘/a’, $current_file);
    $current_filename=substr(basename($current_file_add_a),1);

    Hope that you will correct this (hopefully by finding better solution), if you won’t I hope it will help some1.

    P.S.
    I don’t understand why you define $current_filename in line 209 and than not use it, old code leftovers?
    line 209: $current_filename = substr($current_filename, (strrpos($current_filename, “/”) + 1));

    Plugin Author ShortPixel

    (@shortpixel)

    Hi,
    thanks for your message, sorry for my slow reply!

    Would you mind contacting us directly here, we’d like to run some tests together with you. If everything goes well then we’ll include your change in the live version of the plugin.

    Thanks, I look forward to hearing from you,
    Alex

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using basename breaks UTF-8 filenames’ is closed to new replies.