onlyican Posted September 5, 2006 Share Posted September 5, 2006 HelloI am creating a register formOn the form, I allow a user to upload an imageThe image can be eitherjpg, jpeg, gif, pngI am checking the file extension for thisBUTif somoene has a BITMAP and they manually change the file extension to jpgthen when it comes to resizing the image, the code will mess upExampleif they changed a BITMAP to .jpgthen when it reaches a line of code lineimagecreatefromjpeg()it will thow an errorI know I can stop this by using @imagecreatefromjpegBUTis there a way to check the actual type of image they are uploading without using the file extension Link to comment https://forums.phpfreaks.com/topic/19785-checking-is-jpg-is-really-a-jpeg/ Share on other sites More sharing options...
ober Posted September 5, 2006 Share Posted September 5, 2006 Not sure, never used it, but you could try this: http://www.php.net/manual/en/function.image-type-to-extension.php Link to comment https://forums.phpfreaks.com/topic/19785-checking-is-jpg-is-really-a-jpeg/#findComment-86511 Share on other sites More sharing options...
AndyB Posted September 5, 2006 Share Posted September 5, 2006 getimagesize() is easy enough. it returns a variable indicating the real file type, regardless of what the extension is. Link to comment https://forums.phpfreaks.com/topic/19785-checking-is-jpg-is-really-a-jpeg/#findComment-86523 Share on other sites More sharing options...
paul2463 Posted September 5, 2006 Share Posted September 5, 2006 you could also try this[code]<?phpif (exif_imagetype('image.jpeg') != IMAGETYPE_JPEG) { echo 'The picture is not a jpeg';}?>[/code]information taken from <a href="http://uk.php.net/manual/en/function.exif-imagetype.php"> Here </a> Link to comment https://forums.phpfreaks.com/topic/19785-checking-is-jpg-is-really-a-jpeg/#findComment-86525 Share on other sites More sharing options...
obsidian Posted September 5, 2006 Share Posted September 5, 2006 if you're wanting to run a check on upload, just check the [i]type[/i] of the file in the $_FILES array. if it's image/jpeg, you should be good. keep in mind that this key of the array returns the MIME type of the file, so you've got to know what you're looking for first ;-) Link to comment https://forums.phpfreaks.com/topic/19785-checking-is-jpg-is-really-a-jpeg/#findComment-86543 Share on other sites More sharing options...
onlyican Posted September 5, 2006 Author Share Posted September 5, 2006 Thanks for your repliesThis is for an upload[code]<?php//First I am checking the file extension$file_ext = substr($_FILES['ufile']['name'], strrpos($_FILES['ufile']['name'], '.')+1); //then I am using getimagesize() to work it outlist($width, $height, $type) = getimagesize($_FILES["ufile"]["tmp_name"]);//The type returns the ID number//so using this array, it works out the file type $types = array(1 => 'GIF', 2 => 'JPG', 3 => 'PNG', 4 => 'SWF', 5 => 'PSD', 6 => 'BMP', 7 => 'TIFF(intel byte order)', 8 => 'TIFF(motorola byte order)', 9 => 'JPC', 10 => 'JP2', 11 => 'JPX', 12 => 'JB2', 13 => 'SWC', 14 => 'IFF', 15 => 'WBMP', 16 => 'XBM');//then the file extension is$real_file_type = $types[$type];?>[/code]This should help anyone else who wants thisWhich are the only images I am allowing to uploadThanks for all your help Link to comment https://forums.phpfreaks.com/topic/19785-checking-is-jpg-is-really-a-jpeg/#findComment-86555 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.