Ask your Symfony questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How does Symfony 1.0 check mime-type? Symfony


A friends sends me a question. He is working on a Symfony 1.0 site, and he has added a validator to a form that allows images to be uploaded. He is restricting the images to jpeg. Some jpeg images are accepted, and others are rejected. He can not figure out why some jpeg images are being rejected, while others are accepted. So how does Symfony 1.0 figure out the mime type? Is this a bug? How could we echo the mime-type to the screen?

Answers (3)


Ender Technology answers:

It's from the browser submitted MIME type. The MIME type can be detected differently between browsers/OS's. Certain files may not match a MIME type or may be specific like JPEG2000 and not match the basic "image/jpeg".

Please see our blog post on this issue and a more secure alternative:

[[LINK href=""]][[/LINK]]

Feedback is welcome!

Rob O.
Ender Tech Corp.


Loban Rahman answers:

Symfony 1.0 gets the mime type from the browser. Hence, different browsers of different operating systems may report them slightly differently. I've found that the following list of mime types tend to cover 99% of the cases.


Also include the following to handle jpeg2000 images as well.


Loban Rahman comments:

Also, if you want to know the mime-type that symfony is getting, assuming you used the following code in your form:

<?php echo input_file_tag('scooby') ?>

Then in your action, you can echo the mime-type with



Jakub Zalas answers:

Dictonary of mime types recognized by symfony 1.0 is stored in mime_types.dat file (in my installation it's located in /usr/share/php/data/symfony/data/mime_types.dat).

I used to have troubles because this file is not complete (some mime types/extension are missing).