I use the following code:
$fileinfo = exif_imagetype($_FILES['file']['tmp_name']);
But this yields a fatal error: undefined function.
Can someone tell me what my error is here? (Using php 5.3.8)
php.net link: http://us3.php.net/manual/en/function.exif-imagetype.php
Its probably because you do not have the EXIF extension loaded in PHP.ini
Put this on a page of its own and load the page; it should show all your php info and wether the EXIF extension is installed.
<?php phpinfo() ?>
Thanks to both of you. I did not have it installed. I mistakenly thought it was a built in.
It's why when writing for others I don't use that function... you can't rely on it being present. Serves no real purpose anyways since getimagesize can return the 'type' just as good, anything user upload you should be running through a gd resample/resize anyways (forcing it to a image format), and nobody bothers putting anything useful in for exif data anyways -- and 99% of the time it just having what camera model it was taken with or a bunch of blank fields.
I was going to try it out over getimagesize because I am just using it confirm mime-types, and it is supposed to be faster for that, according to the php manual. But I probably won't be using it regardless because of it relying on an extension and there being a built in alternative.
function imagetype ( $image )
if ( function_exists( 'exif_imagetype' ) )
return exif_imagetype( $image);
$r = getimagesize( $image );
Thats how you do it.
Very nice, thank you.
This topic is now closed. New replies are no longer allowed.