logo
Ask your Symfony questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$5
How does Symfony 1.0 check mime-type?

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?

This question has been answered.

Lawrence Krubner | 07/26/10 at 4:43pm Edit


(4) Responses

See a threaded view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    07/27/10
    9:03am
    Ender Technology says:

    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:

    http://endertech.blogspot.com/2009/10/symfony-mime-type-file-validation.html

    Feedback is welcome!

    Rob O.
    Ender Tech Corp.

    Previous versions of this answer: 07/26/10 at 5:16pm

  • avatar
    Last edited:
    07/27/10
    9:03am
    Loban Rahman says:

    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.

    image/jpeg
    image/pjpeg
    image/jpg

    Also include the following to handle jpeg2000 images as well.

    image/jp2
    image/jpx
    image/jpm

    Previous versions of this answer: 07/27/10 at 2:25am | 07/27/10 at 2:26am

  • avatar
    Last edited:
    07/27/10
    9:03am
    Jakub Zalas says:

    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).

  • avatar
    Last edited:
    07/27/10
    2:43am
    Loban Rahman says:

    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

    $this->getRequest()->getFileType('scooby')

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.