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.

1 Answer
1

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.

Leave a Reply

Your email address will not be published. Required fields are marked *