Symfony2 - How to validate if the uploaded file is a tex file (LaTex)
latex, mime-types, php, symfony, validation
Solution
I think that the same principles of image validation can be applied here. It's unreliable to trust mime-type since user could plant `php` executable within `image/jpeg`.
For the images this can be verified by using `getimagesize()` function. As for the `LaTeX` you would need some 3rd-party lib what will try to open uploaded file and throw the exception on error (invalid file format, invalid expression, etc...).
Maybe this one: PHPLatex?
Also, which mime-type did you get when you tried uploading file? (@Ahmed's idea)
Problem
I have a file upload function in my Symfony2 project and I would like to validate that the uploaded file is a `.tex` file format => LaTex file. For text/html, I am using: ``` $metadata->addPropertyConstraint('file', new Assert\File(array( 'maxSize' => '100000k', 'mimeTypes' => array("text/html"), 'mimeTypesMessage' => 'Please upload a valid HTM/HTML File', ))); ``` I am trying: ``` $metadata->addPropertyConstraint('file', new Assert\File(array( 'maxSize' => '100000k', 'mimeTypes' => array( 'text/html', 'application/x-tex', 'application/x-latex' ), 'mimeTypesMessage' => 'Please upload a valid HTM/HTML/TEX File', ))); ``` But as soon as I am uploading a .tex file, I am getting the message: ``` Please upload a valid HTM/HTML/TEX File. ``` How can I add Tex file also here? Thank you.