When I upload an image with non-english characters in media uploader it gets incorrectly converted name in wordpress uploads folder but the image link in database is has correct name which results in 404 error.

For example if I upload an image with filename obrázek.jpg, WordPress places it to upload folder like this: obrázek.jpg

The link to the image in wordpress media uploader is correct though: http://localhost/wordpress/wp-content/uploads/obrázek.jpg

I have set up charsets to UTF-8 in PHP, Apache, MySQL and WordPress configuration files.

I think this has something to do with Apache. Do you have any idea how to fix this?

Thank you.


This is well know issue but for some reason it is not resolved since 2013


You can always sanitized filename by yourself using sanitize_file_name filter.

 * Sanitize filename to not brake links with UTF-8 characters
 * WordPress allow to upload files with names containing UTF-8 characters. Some
 * browsers do not handle properly UTF-8 characters in url which causes 404 errors.
 * This filter will remove UTF-8 characters from filename before saving it.
 * @see https://core.trac.wordpress.org/ticket/22363 Bug request
 * @param string $filename Filename
 * @return string Sanitized filename
function sanitize_filename( $filename ) {
    $file_parts = explode( '.', $filename );
    $extension  = array_pop( $file_parts );
    $filename   = sanitize_title( preg_replace( '/[^A-Za-z0-9\-]/', '', join( '.', $file_parts ) ) );

    return sprintf('%s.%s', $filename, $extension);

add_filter( 'sanitize_file_name', 'sanitize_filename' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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