WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] SVG upload not allowed?? (9 posts)

  1. thanatica2
    Member
    Posted 3 years ago #

    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!

  2. ClaytonJames
    Member
    Posted 3 years ago #

    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

  3. thanatica2
    Member
    Posted 3 years ago #

    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?)

  4. ClaytonJames
    Member
    Posted 3 years ago #

    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.

  5. thanatica2
    Member
    Posted 3 years ago #

    I guess I'll try the plugin solution then. Thanks for explaining :)

  6. ClaytonJames
    Member
    Posted 3 years ago #

    You're welcome.

  7. OmegaMan
    Member
    Posted 3 years ago #

    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;
    
    }
  8. thanatica2
    Member
    Posted 3 years ago #

    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.

  9. OmegaMan
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.