Validation failing using PHP's getimagesize function

I'm validating form input and I'm having trouble with the file upload control.  First, here are the conditions :

1 - image must be no larger than 50 x 50 pixels
2 - image must be of type .GIF, .JPG or .PNG

I've been looking at the getimagesize function and it seems to suit my needs just fine in this case.  The filesize validation works as it should but the second validation on type is letting any old file in.  Could be and executable, could be a text file...anything is being accepted and I'm not quite sure why.
Here's my code :
list($width, $height, $type, $attr) = getimagesize($target_path);
if($width > 50 || $height > 50) { 
     $err_msg .= "\\nImage must be no larger than 50 x 50 pixels in size";
     $image_err = true;
     $errors = true;
}
if($type < 1 && $type > 3)  {
     $err_msg .= "\\nImage must be of type .GIF, .JPG or .PNG";
     $image_err = true;
     $errors = true;
}
if($image_err == true)  { unlink($target_path);  }

Open in new window


According to Jesus Zamora's comment on the PHP reference site, type 1 should be .GIF, 2 should .JPG and 3 should be .PNG.  Here's a link to the page :

http://php.net/manual/en/function.getimagesize.php

Any help in the matter would be much appreciated.

duder78Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael701Commented:
Without looking up the command I question your logic


if($type < 1 && $type > 3)  {


should this be an 'OR' statement


if($type < 1 || $type > 3)  {
0
Salih MaouiSenior Software DeveloperCommented:
in upload for try

if ($_FILES["imagefile"]["type"] == "image/jpeg" || $_FILES["imagefile"]["type"] == "image/gif" || $_FILES["imagefile"]["type"] == "image/png") {  }

good luck
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Michael701Commented:
After looking up the command, YES

if($type < 1 || $type > 3)  {
0
duder78Author Commented:
My bad, it was supposed to be ||.  Doesn't help matters though.  maosalah, i'm going to try your code and see what happens.

0
duder78Author Commented:
That's the ticket man.  I'll just use getimagesize to validate the image size then.  Thanks alot!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.