Support » Plugin: User Submitted Posts » Image file names with foreign characters

  • Resolved strx


    Thanks for a really great plugin! However I have a problem with the image upload. It occurs when an image is uploaded with a name containing the Swedish letters å, ä and ö. The image is saved but apparently with the wrong encoding, and it doesn’t show up when viewing the post. Is there a way I can check and modify the image name before upload?

Viewing 5 replies - 1 through 5 (of 5 total)
  • While at it, it would be good to make sure to filter out spaces, too.
    A tips is to simply urlencode whatever you get from the user.

    Tor-Bjorn, can you point me to more info on this “urlencode”?

    Plugin Author Jeff Starr


    Glad to help. To modify the name (and other details, optional) of each submitted file, you can use the filter hook, usp_insert_attachment_data. Here is complete documentation on using filter hooks, if you are unfamiliar.

    @rjpivonka I’m not sure it would solve this particular situation, whether you’ll get valid filenames that way, or not. Perhaps an approach is what social networks do all the time: They just generate pseudorandom strings as filenames. Whatever they got from the user may be kept simply as meta-data.
    urlencode is a PHP function:

    Plugin Author Jeff Starr


    Just to follow up with this, here is an example of how to access the attachment variables for each uploaded image:

    function usp_customize_attachment_data($attachment) {
    		$attachment includes:
    		array(5) {
    		  string(10) "image/jpeg"
    		  string(13) "example.jpg"
    		  string(13) "example.jpg"
    		  string(7) "inherit"
    		  string(67) ""
    	// do your thing..
    	return $attachment;
    add_filter('usp_insert_attachment_data', 'usp_customize_attachment_data');

    I hope it helps!

    • This reply was modified 4 years, 6 months ago by Jeff Starr.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Image file names with foreign characters’ is closed to new replies.