Can't upload svg file (forbidden mime type)

I get the message “Forbidden mime type” when I try to upload a svg file to a page in the Panel. I use version 2.2.2 of the Toolkit, Kirby and Panel. I have the problem on both my MAMP and an external Ubuntu / Apache server.

Tried to add:

AddType image/svg+xml svg
AddType image/svg+xml svgz

to the .htaccess just in case, but still the same problem.
I can use the svg image in the Panel and on the page if I manually put it in the folder structure, but I want to use the Panel to add the file.

Which PHP version are you using? Depending on that, you need to add the SVG type to different files.

On my MAMP i use PHP 5.6.2, and on the external server I use PHP 7

Could you please try what this code snippet echoes when applied to your SVG file:

echo f::mime('your.svg');

You can put this somewhere in your template or snippet and place the SVG file into the root directory of your site.

I get “text/html”…

So it’s what I thought. Hm, that’s really strange. I honestly don’t know how to fix it in PHP 5.6, as the MIME detection is built-in to PHP.
Hopefully someone else had this problem before and can give some input.

This is really weird.
If I look in the mime.types file for my local apache2 server (/etc/apache2/mime.types) i find this two lines about svg:

# application/vnd.oipf.dae.svg+xml
image/svg+xml					svg svgz

But still getting text/html for the svg mime type. I tried to remove the # for application/vnd.oipf.dae.svg+xml and restarted the server. But still the same.
What to do?

The Apache MIME file shouldn’t contribute anything to the PHP MIME detection. Maybe your system magic file, but as far as I know, PHP has its own set of information about file types.

I now tried to upload a svg to a Kirby installationen on a third and different server. Still the same problem. I can’t be the only one having this struggle?

Hm, I tried it on two of my servers and actually they have this problem as well. But I think it has worked before. Very strange.

But actually it is very difficult to detect the MIME type of an SVG file. It just looks like HTML. :smiley:

It’s quite strange that it doesn’t work on Mamp, I have no problem on my local install. Also just tested it on a server, no problem, either.

I just tested it again. It seems like the detection algorithm PHP uses also checks whether the SVG file has a <?xml version="1.0" encoding="UTF-8" standalone="no"?> line at the beginning. When run through SVGO (which removes that) or just when deleting that line, PHP detects the file as HTML.

1 Like

I have no problem uploading an svg file with that line removed though, so that is probably not the problem although it would be interesting to know if the file you want to upload misses the xml tag.

That did the trick!
But that is just annoying. I run all my svg through the optimizer at http://petercollingridge.appspot.com/svg-editor and tell my clients to do the same. But now I need to tell them to add this line… or not to optimize (which is probably easier but boring).

But thank you so much for the help!

What settings do you use to optimize the files? I tested this and could still upload an optimized file (tested on localhost and two remote servers). So I wonder if there is something else to it.

In most cases I use the “Extreme (may alter image quality)”.

I tried that with a couple of files, and all files could be uploaded. Having said that, the mime type of these files is recognized as text/plain, not text/hmtl, that’s probably why it does work.

Yes, the Panel only blocks HTML, PHP, EXE types and files with extension txt (Kirby content file). Every other type is fine, no matter what it actually is.

1 Like

That did the trick for me too. Without the xml declaration it wouldn’t work in MAMP, nor on my client’s server.

NB: you don’t need to explicitly set standalone="no"because it’s the default value.