Bead
Bead

Reputation: 363

Determine file extension of an image that is missing an extension

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

Answers (2)

Jocelyn
Jocelyn

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

Musa
Musa

Reputation: 97672

getimagesize expects a file name as the first argument

Upvotes: 1

Related Questions