Reputation: 363
I have some images on my system that were saved without a file extension, they appear in the format of "FILENAME." (Note the period)
I am trying to use getimagesize(); but it is erroring out telling me that "Filename cannot be empty"
Here is a sample of the code I am using
$contents = file_get_contents($localFile);
$imageData = getimagesize($contents);
// $imageData[2] will contain the value of one of the constants
$mimeType = image_type_to_mime_type($imageData[2]);
$extension = image_type_to_extension($imageData[2]);
Upvotes: 0
Views: 634
Reputation: 11393
Look at the documentation: http://php.net/getimagesize
getimagesize() is expecting a filename as first parameter, not the contents of the image file.
Try:
$imageData = getimagesize($localFile);
// $imageData[2] will contain the value of one of the constants
$mimeType = image_type_to_mime_type($imageData[2]);
$extension = image_type_to_extension($imageData[2]);
Upvotes: 1