WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Uploaded image with accents in name, image don't show in Safari 6 (5 posts)

  1. bitox
    Member
    Posted 2 years ago #

    Hello,
    You can see the page http://www.soulcie.fr/portfolio/a-qui-ira-lump/ (Gridlocked theme). With Safari, the image don't show, because he can't get the URL http://www.soulcie.fr/wp-content/uploads/2012/08/120820_pre%CC%81sidence-ump-bousier-scarabe%CC%81es.jpg
    Can you help me determine if it is a WP related problem (should remove special characters at upload), a Gridlocked theme problem… or Safari is lame ?
    Thank you

  2. codingpet
    Member
    Posted 2 years ago #

    http://www.soulcie.fr/wp-content/uploads/2012/08/120820_présidence-ump-bousier-scarabées.jpg

    http://www.soulcie.fr/wp-content/uploads/2012/08/120820_présidence-ump-bousier-scarabées.jpg

    I can't see any differences for the two URL but they are different if you just copy it. The first one is correct while the second is broken. The é in the two URL are different if you view the two URL in notepad.

    It will be good to not use german characters in image name. Further problems will happen if there are special characters in image name(for example, some hosting will encode these characters if you upload via FTP but will not encode it when uploading in wordpress. This will cause different image URL in hosting and wordpress database when you transfer/restore site).

  3. bitox
    Member
    Posted 1 year ago #

    Okay, so your advice is not to use special characters in the file names. Why wouldn't wordpress media uploader rename the special characters? BTW, they're french :-)
    Thanks,

  4. memovera
    Member
    Posted 1 year ago #

    This wp function works for me: remove_accents. Hope it helps :D
    Example:
    http://www.uv.mx/personal/gvera/wordpress-remove-special-characters-from-uploaded-files/

  5. bitox
    Member
    Posted 1 year ago #

    Thanks for the hint!
    It worked for me with the following code in functions.php

    function sanitize_filename_on_upload($filename) {
    $ext = end(explode('.',$filename));
    // Replace all weird characters
    $sanitized = preg_replace('/[^a-zA-Z0-9-_.]/','', substr($filename, 0, -(strlen($ext)+1)));
    // Replace dots inside filename
    $sanitized = str_replace('.','-', $sanitized);
    return strtolower($sanitized.'.'.$ext);
    }

    add_filter('sanitize_file_name', 'sanitize_filename_on_upload', 10);

    Cheers!

Topic Closed

This topic has been closed to new replies.

About this Topic