2

So, I have 2 sites. One in production, and the another in development. They have the same content and uploads.

In production, images with names containing æ, ø, or å gets the character replaced with something else, for example ø get replaced with ø, and then saved in the upload folder. And it works! Wordpress somehow gets the right image when I request it.

E.g: wp-content/upload/2015/01/interiørtips.jpg will display the image interiørtips.jpg.

In the database, the references to the images are saved normally, including the special characters; æøå is used in the name, not some other obscure character combination. This means that the database is ok.

I exported all the content from production to a fresh database in development, but now every image which has either an æ, ø, or å in it wont load the same way as in production. The request wp-content/upload/2015/01/interiørtips.jpg won't load anything, but wp-content/upload/2015/01/interiørtips.jpg will. This is opposite of the behavior in production.

Does anyone know anything about this?

EDIT: I'll probably just some rename tool. But, if anyone has any insights, please share.

2
  • 1
    Right. WordPress replace only a small list from strings. If your language have different strings, then is a Dropin or plugin helpful, that replace the strings on upload. Use the filter hook sanitize_file_name. See this Dropin as example github.com/bueltge/de_DE.php/blob/master/de_DE.php
    – bueltge
    Jan 9, 2015 at 18:31
  • 1
    Oh, this is a good one... Can replicate issues in my local setup and I am reasonably sure I got no bad config issues (dealing with cyrillic and such at times).
    – Rarst
    Jan 10, 2015 at 14:43

1 Answer 1

4

WP sanitize_file_name() function doesn't handle those characters by default.

You can add filter and sanitize those to avoid encoding issues.

function mamaduka_sanitize_file_name( $filename ) {
    $filename = strtr($filename, 'ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïñòóôõöøùúûüýÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƒƠơƯưǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǺǻǼǽǾǿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyyAAAAAAAECEEEEIIIIDNOOOOOOUUUUYsaaaaaaaeceeeeiiiinoooooouuuuyyAaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIiIJijJjKkLlLlLlLlllNnNnNnnOoOoOoOEoeRrRrRrSsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZzsfOoUuAaIiOoUuUuUuUuUuAaAEaeOo');

    return $filename;
}
add_filter( 'sanitize_file_name', 'mamaduka_sanitize_file_name' );

Code example for this trac comment - https://core.trac.wordpress.org/ticket/16330#comment:22.

1
  • If I upload a file with the name åøæ.jpg, It gets changed to UNUtUN.jpg. That doesn't seem right from what I can tell.
    – ptf
    Jan 12, 2015 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.