Click to See Complete Forum and Search --> : Verifying image types (jpg, png, gif)


sc_king
02-03-2008, 03:10 AM
My Form
echo "Main Image: <br />";
echo "<input name='uploaded[]' type='file' /><br /><br />";
echo "Image 2: <br />";
echo "<input name='uploaded[]' type='file' /><br /><br />";
echo "Image 3: <br />";
echo "<input name='uploaded[]' type='file' /><br /><br />";
echo "Image 4: <br />";
echo "<input name='uploaded[]' type='file' /><br /><br />";

I will pass the array uploaded into my function.
How can I verify the types to only include those which I have mentioned?

toenailsin
02-03-2008, 04:02 AM
is this what your looking for?

$File_Extension = strtoupper(ereg_replace(".*\.(.*)$","\\1", $FileName));

NogDog
02-03-2008, 04:55 AM
getimagesize (http://www.php.net/getimagesize)() can be used to determine most common types of image files.

sc_king
02-04-2008, 02:37 PM
Will these allow me to find if a person uploaded a wrong filetype?

Is this the best way?

NogDog
02-04-2008, 03:41 PM
getimagesize() is probably the most complete method (within the built-in PHP functions). It actually analyzes the file contents, rather than just looking to see what the file suffix is.