• Resolved thanatica2

    (@thanatica2)


    I’m trying to put an SVG image into a post, but I can’t upload it.

    “Harajuku map.svgz” has failed to upload due to an error
    Sorry, this file type is not permitted for security reasons.

    What gives?! It’s just an image!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Clayton James

    (@claytonjames)

    You can overcome the security warning by adding this to your current themes functions.php file.

    add_filter('upload_mimes', 'custom_upload_mimes');
    
    function custom_upload_mimes ( $existing_mimes=array() ) {
    
    	// add the file extension to the array
    
    	$existing_mimes['svg'] = 'mime/type';
    
            // call the modified list of extensions
    
    	return $existing_mimes;
    
    }

    Then you should be able to upload files with an .svg extension

    Thread Starter thanatica2

    (@thanatica2)

    Thanks. I didn’t realize this was workaroundable 🙂

    There’s just 2 more things bothering me about this:

    1) Doing this in a theme makes uploading SVG dependent on the selected theme. Having to do this for multiple sites produces more boilerplate code, plus a theme is not where this function belongs, iyam.

    2) Why is SVG blocked in the first place? (Or rather, looking at the code: why is SVG not whitelisted?)

    Clayton James

    (@claytonjames)

    1) Doing this in a theme makes uploading SVG dependent on the selected theme.

    Well, one alternative would be to edit core file(s). Which of course would be overwritten on an upgrade. We all know the upset that causes to adventurous folks who like to edit the default theme instead of a child theme. Another solution might be to look for/make a plugin that allows you to add mime types?

    plus a theme is not where this function belongs, iyam.

    That’s debatable. I agree a plugin solution might be easier for those who actually need it.

    Why is SVG blocked in the first place? (Or rather, looking at the code: why is SVG not whitelisted?)

    Could be related to embeds and -or- user roles with permissions related to unfiltered html use? I guess I don’t know what the right answer should be. You may want to do a little more searching for a better answer on that.

    Might be something in here: http://wordpress.org/search/+.svg+support?forums=1

    Here’s the wp functions.php file if you want to have a look at that.

    Thread Starter thanatica2

    (@thanatica2)

    I guess I’ll try the plugin solution then. Thanks for explaining 🙂

    Clayton James

    (@claytonjames)

    You’re welcome.

    Clayton Thanks!
    I needed to upload Silverlight Xap files as well and used:

    add_filter('upload_mimes', 'custom_upload_mimes');
    
    function custom_upload_mimes ( $existing_mimes=array() ) {
    
    	// add the file extension to the array
    
    	$existing_mimes['xap'] = 'mime/type';
    
            // call the modified list of extensions
    
    	return $existing_mimes;
    
    }
    Thread Starter thanatica2

    (@thanatica2)

    I’m sure the mimetype for silverlight is not mime/type but rather application/x-silverlight-app 🙂

    A plugin named “PJW Mime Config” works quite well, I might add.

    oops! Bad paste thanks thanatica #2 for pointing it out. 🙂 I will look into the plugin.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘SVG upload not allowed??’ is closed to new replies.