WordPress.org

Ready to get started?Download WordPress

Forums

Upload Files - name with special characters (2 posts)

  1. Cristiano
    Member
    Posted 3 years ago #

    Hi friends,

    I just realized that when a upload a file that has a name with special characters, its name is changed in the uploads directory, but not in his URL name... so I get a 404 page error...

    I mean, if the file name is cára.pdf for exemple, it changes to cára.pdf at the uploads directory... but WP keeps its URL name cára.pdf

    Is there a way to solve it? WP could change both, the file name and the file URL or change neither... but if it changes just one of them, I have a big problem!

    Thanks!!!

  2. magollo
    Member
    Posted 2 years ago #

    Hello Cristiano, you can fix that by adding this script to your themes function.php file.

    add_filter('sanitize_file_name', 'sa_sanitize_spanish_chars', 10);
    
    function sa_sanitize_spanish_chars ($filename) {
    	$spanish_chars = array( '/á/', '/é/', '/í/', '/ó/', '/ú/', '/ü/', '/ñ/', '/Á/', '/É/', '/Í/', '/Ó/', '/Ú/', '/Ü/', '/Ñ/', '/º/', '/ª/' );
    	$sanitized_chars = array('a', 'e', 'i', 'o', 'u', 'u', 'n', 'A', 'E', 'I', 'O', 'U', 'U', 'N', 'o', 'a');
    	$friendly_filename = preg_replace($spanish_chars, $sanitized_chars, $filename);
    	return $friendly_filename;
    }

    You can check my website that is working and wordpress and its already fixed.

Topic Closed

This topic has been closed to new replies.

About this Topic