Monday, July 11, 2011

How to solve one problem with file uploading

Today I have one problem with file uploading. When I try to use method Symfony\Component\HttpFoundation\UploadedFile::guessExtension() it has always returned null. If you have the same problem you should include php_fileinfo extension in your php.ini file. For those who are insterested how I have solved this problem I wrote short prehistory.

I have left hours for solving this problem and saw that Symfony\Component\HttpFoundation\File::guessExtension() (parent class of Symfony\Component\HttpFoundation\UploadedFile):


After diving into Symfony\Component\HttpFoundation\File::getMimeType() I have trapped to Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser::__construct(). And we see that here it MimeTypeGuesser creates an instance of FileinfoMimeTypeGuesser:

 

And the last one we see here:


It uses \finfo() that belongs to php_fileinfo extension. So you should include it in your php.ini file to solve the problem.