Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

VertexBuffer's avatar

Laravel Image/Mimes Validation fails for SVG

So I've got an image upload endpoint, and it works with a majority of image formats I can throw at it EXCEPT SVG.

For whatever reason, it appears to just not work.

I've tried both rules;

mimetypes:image/jpeg,image/png,image/svg+xml

mimes:jpeg,png,svg

But neither work for SVG. It constantly gives the error; "The file must be a file of type: image/jpeg, image/png, image/svg+xml."

But if you look at the content-type of my request, you can see it is svg. https://i.imgur.com/dBK3yPN.png

So I'm not really sure what's going on here?

0 likes
4 replies
VertexBuffer's avatar

I should add as well the even more confusing part is my tests for the upload route work fine when I give it an SVG like so; $file = UploadedFile::fake()->create('image.svg')

So I'm really confused as to what the issue is to be honest.

VertexBuffer's avatar

UPDATE: It would appear you need this at the top of your SVG file in order to make it work. <?xml version="1.0" encoding="utf-8"?>

This is pretty annoying so hopefully there is still a solution to remove this so I can have just pure <svg></svg> tags!

3 likes

Please or to participate in this conversation.