• Hello,

    For latin version of wordpress, uploaded files in the media librabry can content special characters in filenames.

    Then for some browsers the links to download files are broken.

    I look for a solution in the web and try to use this in my functions.php theme file :

    add_filter(‘sanitize_file_name’, ‘sa_sanitize_chars’, 10);
    function sa_sanitize_chars($filename) {
    return remove_accents($filename);
    }

    But it does’nt work, special caracheter are still present in filemane.

    Thanks for you help

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    If charsets are properly handled, this should not be an issue, but doing so properly is difficult to achieve, so we have this problem ??

    What charset is your site using? (It should ideally be utf8, but converting existing content to it is not trivial) The remove_accents() function only works properly with utf8 or ISO-8859-1. You can use the PHP iconv module to convert strings to utf8 if needed.

    Be sure whatever is outputting the links actually uses the sanitize_file_name() function or your filter function will never be called.

    If your links are properly utf8, you can also encode your links with utf8_uri_encode() which should result in links with accents working in all browsers, even if the browser mis-manages charsets.

Viewing 1 replies (of 1 total)
  • The topic ‘Remove accent from filename during upload’ is closed to new replies.