The UploadedFile object is ultimately extended from Symfony\Component\HttpFoundation\File\UploadedFile , which gets / sets mimeType from The type of the file as provided by PHP .
To access this type of mimeType you need to call $file->getClientMimeType()
However, in the Symfony docblock for a function, it offers:
The mime client type is extracted from the request from which the file was downloaded, so it cannot be considered safe.
For a reliable mime type, use getMimeType () instead (which guesses about the mime type based on the contents of the file).
In your case, however, $file->getMimeType() , which should be trusted and guess the mime type from the content, however, it returns something as if it could not determine the mime type, being "application / octet-stream"
Additional Information
To help you decide. Basically, getClientMimeType() will return the mime type specified by the browser.
The getMimeType call guesses the mime type using two different methods that I can see:
Using the mime binary method, looking at the result of the following file -b --mime %s 2>/dev/null command, if supported.
The second method uses finfo_open if it exists inside php.
If both 1. and 2. exist in your system, then from what I see there will be a preference, and 1. will be a backup.
I would personally support getMimeType() results for security. However, it would be another interesting question: "How reliable is the detection of the mime-browser type and what methods are used" :-)
Updated example
I will give an example for you.
For me, doing a check on "DropboxInstalled.dmg", here are my results:
$finfo = new \finfo(FILEINFO_MIME_TYPE); echo $finfo->file('./DropboxInstaller.dmg');
returns application/x-iso9660-image