• ResolvedPlugin Author Benbodhi

    (@benbodhi)


    In the recent releases of WordPress, there was changes made to the mime type handling to make sure that files have the extension they say they do (read more in this post).

    This poses an issue for SVG files without the <xml> tag in them.

    SVG is actually XML, and WordPress now requires us to have a line such as <?xml version="1.0" encoding="utf-8"?> in our SVG file when opened in a code editor. Some graphic software does remove this when saving/exporting our SVG.

    So, if you receive an upload error “Sorry, this file type is not permitted for security reasons.”, you simply need to open your SVG file in a code editor like sublime text and add the xml tag mentioned above to the first line and save. Then try uploading again.

    I will be looking into some way to avoid this issue if I can implement it into my plugin, but for the time being, this is the solution it seems.

    Thanks for your support and patience!

Viewing 15 replies - 16 through 30 (of 31 total)
  • That’s great @mainpart! I’ll try it in a while ??

    Thanks!

    So whatsup, when will the fix be ready? ??

    Plugin Author Benbodhi

    (@benbodhi)

    Long story, but been unable to spend the time I’d like on the plugin for a while. Injuries, hospital, moving house (and country), other work… lots of things in my plate and I’m the sole developer.

    I’m going to try and dedicate some time in the coming week or so.

    I used this plugin on many websites. Now I’m mooving to a new plugin because I can’t upload the optimized images anymore. Other plugins don’t have this issue. Please fix it.

    I exported the SVG through Illustrator and optimised it using SVGOMG. Tried uploading it and it didn’t work. Opened up the SVG in Notepad++ and added the first line of code as suggested here. It worked. So yes, only adding that line should be enough as per my experience.

    • This reply was modified 5 years, 8 months ago by Salman Ravoof.

    As I see it the fix for this problem with the Avada theme (and possibly others) is to increase the priority number when you register the upload_mimes filter.

    Something like

    add_filter( 'upload_mimes', 'bodhi_svgs_upload_mimes', 11 );

    does the trick for me. This does break SVG-font upload support for the theme, but with WOFF support being near universal I don’t think that is much of an issue.

    Plugin Author Benbodhi

    (@benbodhi)

    Thanks for your feedback and tips @thomaslhotta and @salmanravoof

    Hi @benbodhi I added the code mentioned to the SVG file but still cannot get it to upload into the media library. I am using the Avada theme. I saw @thomaslhotta ‘s post above, but am not sure where to add that code.

    @sshattersley

    In case you’re still struggeling: It needs to be added to your theme (preferably child theme)’s functions.php. @thomaslhotta’s code bit alone probably won’t do anything.

    You’ll need something like this (do correct me if I’m wrong):

    function bodhi_svgs_upload_mimes($mime_types) {
        $mime_types['svg'] = 'image/svg+xml';
        return $mime_types;
    }
    add_filter('upload_mimes', 'bodhi_svgs_upload_mimes', 11);

    See Plugin API/Filter Reference/upload mimes – WordPress Codex for more details about the upload_mimes filter.

    • This reply was modified 5 years, 6 months ago by mauri94.

    I noticed that some services add a comment line at the top when you export the code. So, you need to make sure you add the line above that comment if there is one. Otherwise, you still fail.

    Plugin Author Benbodhi

    (@benbodhi)

    Thanks for the feedback @prodport, I appreciate that.

    Hoping to release an update to fix all this asap.

    jumzoid

    (@jumzoid)

    Thanks for the great plugin @benbodhi – works sweet on other sites I’ve done that don’t use Avada.
    Thanks @mainpart for the Avada fix. Worked a treat. ??

    This isn’t working for me.

    The image I’m trying to upload is already has the header <?xml version=”1.0″ encoding=”utf-8″?>. Any ideas? :-S

    Plugin Author Benbodhi

    (@benbodhi)

    Hey @yandoos can you please provide your SVG file.
    And it would be better to start your own topic.
    Thanks

    In-line with this issue any ideas on how to remove “<?xml version=”1.0″ encoding=”utf-8″?>” in the frontend display?

    I am getting an error when validating and checking the website in https://validator.w3.org/.

    Error Message:
    Saw <?. Probable cause: Attempt to use an XML processing instruction in HTML. (XML processing instructions are not supported in HTML.)

    Thanks

Viewing 15 replies - 16 through 30 (of 31 total)
  • The topic ‘Sorry, this file type is not permitted for security reasons.’ is closed to new replies.