Andy-H Posted November 19, 2008 Share Posted November 19, 2008 Does anyone know of one to get the image type from an fopen or from an image url? Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/133322-solved-function-to-get-image-type/ Share on other sites More sharing options...
gevans Posted November 19, 2008 Share Posted November 19, 2008 http://uk2.php.net/manual/en/function.exif-imagetype.php That takes you to the exif_imagetype() page of php.net Very easy to use, but you do need to have EXIF installed on the server. Link to comment https://forums.phpfreaks.com/topic/133322-solved-function-to-get-image-type/#findComment-693371 Share on other sites More sharing options...
Andy-H Posted November 19, 2008 Author Share Posted November 19, 2008 thanks Link to comment https://forums.phpfreaks.com/topic/133322-solved-function-to-get-image-type/#findComment-693372 Share on other sites More sharing options...
Andy-H Posted November 19, 2008 Author Share Posted November 19, 2008 exif isnt installed Link to comment https://forums.phpfreaks.com/topic/133322-solved-function-to-get-image-type/#findComment-693376 Share on other sites More sharing options...
gevans Posted November 19, 2008 Share Posted November 19, 2008 You could work backwards. Once you have the URL, use substr to return the last 4 characters $image = "example.jpg"; $ext = substr($image, -4); if($ext == ".jpg") echo "This is a jpg"; else echo "This is a different image type"; This will only work if you know what extensions you are looking for Link to comment https://forums.phpfreaks.com/topic/133322-solved-function-to-get-image-type/#findComment-693379 Share on other sites More sharing options...
Andy-H Posted November 19, 2008 Author Share Posted November 19, 2008 I need the header image type because they have the .jpg extension for all images yes some are png, I only want to display the jpg images. Link to comment https://forums.phpfreaks.com/topic/133322-solved-function-to-get-image-type/#findComment-693380 Share on other sites More sharing options...
gevans Posted November 19, 2008 Share Posted November 19, 2008 OK, try this.... <?php list($width, $height, $type, $attr) = getimagesize("img/flag.jpg"); echo $type; ?> Link to comment https://forums.phpfreaks.com/topic/133322-solved-function-to-get-image-type/#findComment-693385 Share on other sites More sharing options...
Andy-H Posted November 19, 2008 Author Share Posted November 19, 2008 k ty m8 will do when I get back to college. Link to comment https://forums.phpfreaks.com/topic/133322-solved-function-to-get-image-type/#findComment-693418 Share on other sites More sharing options...
ILMV Posted November 19, 2008 Share Posted November 19, 2008 Hang on... what if the image is .jpeg? http://en.wikipedia.org/wiki/JPEG Link to comment https://forums.phpfreaks.com/topic/133322-solved-function-to-get-image-type/#findComment-693420 Share on other sites More sharing options...
Andy-H Posted November 19, 2008 Author Share Posted November 19, 2008 Got it, ty for help $fp = fopen($file, 'r'); if ($fp){ $type = getimagesize($file); $type = $type['mime']; if ($type == "image/jpeg"){ Link to comment https://forums.phpfreaks.com/topic/133322-solved-function-to-get-image-type/#findComment-693436 Share on other sites More sharing options...
gevans Posted November 19, 2008 Share Posted November 19, 2008 Hang on... what if the image is .jpeg? http://en.wikipedia.org/wiki/JPEG Then he would check it against '.jpg' and 'jpeg' (i didn't choose four characters fr the dot) Link to comment https://forums.phpfreaks.com/topic/133322-solved-function-to-get-image-type/#findComment-693450 Share on other sites More sharing options...
Andy-H Posted November 19, 2008 Author Share Posted November 19, 2008 Besides, I could just use: $file = "http://www.example.com/pic.jpeg"; $file = explode(".", $file); $index = count($file) - 1; $extention = $file[$index]; Link to comment https://forums.phpfreaks.com/topic/133322-solved-function-to-get-image-type/#findComment-693456 Share on other sites More sharing options...
gevans Posted November 19, 2008 Share Posted November 19, 2008 Besides, I could just use: $file = "http://www.example.com/pic.jpeg"; $file = explode(".", $file); $index = count($file) - 1; $extention = $file[$index]; Yea, there's a few options, but you're $type['mime'] seems like the ebst option for you Link to comment https://forums.phpfreaks.com/topic/133322-solved-function-to-get-image-type/#findComment-693467 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.