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?
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:
Feedback is welcome!
Ender Tech Corp.
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.
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
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).