PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
They assume files only have one dot in them ( ? someclass.class.php ?), the second one only looks for the string "jpeg" in the filename bit after the dot too.... that's a little pointless.
$allowed = array('jpg', 'jpeg'); //Can add to this
$ext = substr($filename, strrpos($filename, '.')+1);
if (in_array($ext, $allowed)) //I never remember if haystack comes first or second
{
//OK
}
feyd wrote:
getimagesize() should be used to determine image type, not extension.
Hi, I tryed for hours last night to us this, but with no more luck than before, I'm really new to this, sorry to ask, but could someone show me how I would use getimagesize() to find the image type and compare it to a list of supported image types?
Returns an array with 4 elements. Index 0 contains the width of the image in pixels. Index 1 contains the height. Index 2 is a flag indicating the type of the image: 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. These values correspond to the IMAGETYPE constants that were added in PHP 4.3.0. Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.