I have a laravel 4.1 project running on PHP 5.3.28 and I am trying to find a way to get the file extension from a certain image that fails whenever I use guessExtension()
like so:
$format = Input::file('image')->guessExtension();
Every other image I've tried uploading has had no problem using guessExtension()
, but it seems Symphony is unable to recognize the mimeType
for this specific image:
object(Symfony\Component\HttpFoundation\File\UploadedFile)[9]
private 'test' => boolean false
private 'originalName' => string 'herewithme.png' (length=14)
private 'mimeType' => string 'application/octet-stream' (length=24)
private 'size' => int 0
private 'error' => int 1
and my application fails with the following message:
The file "" does not exist
I was thinking about doing something like this:
$filename = Input::file('image')->getClientOriginalName();
if(strpos($filename, '.png') !== false)
{
$format = 'png';
}
elseif(strpos($filename, '.jpg') !== false)
{
$format = 'jpg';
}
However, I'm afraid of the random case that a file might cause problems from being named something like pdf.png.jpg
(or something to that effect), so I'm hesitant about getting the file format this way. Can anyone think of a better way to do this?