PHP - I need to have the IF statement check multiple things (parameters)...

Christopher

New member
...properly, help, suggestions? NOTE: yahoo was shortening some of the code so I took out the proper php OR symbols and put OR instead...don't know if it'll work.

I have a form that allows you to upload up to 10 pictures at a time to my site. Everything works fine so far with the script except the following...

Naturally to avoid issues I need to dis-allow certain image types or movies for example, from being uploaded.To do this I have the following code.

// These variables will be used to check against in a bit (Only a few used here so you get the idea)
$check1 = "image/gif"; $check2 = "image/agif"; $check3 = "image/jpg"; $check4 = "image/jpeg";

// Now Check that an image exist (I left out this code because you guys don't need to see it), and if the image is one of the acceptable formats (checks)
if ($image_size1==TRUE&&$image_type1==$check1OR$image_type1==$check2OR$image_type1==$check3OR$image_type1==$check4)
{
// Start inserting the image into the database here because it passed the if statement
}
else
echo "some error message here if you want..."

NOW THIS IS WHAT I NEED HELP ON --- So the above code all works except the problem is I have 20 file types I want to allow and need to check against, as well as this code all copied and changed to upload pictures 2 -> 10.

IS THERE a way to make something like the following work??

// What I want to check against, everything all put into one thing so I don't have to write it for all 10 pictures I'm checking
$checkall = array("image/jpg","image/gif","image/jpeg","etc...")

// The new IF statement (first little part works already remember that, look at the part after the &&)
if ($image_size1==TRUE&&$image_type1==$checkall)
{
// Start inserting the image into the database here because it passed the if statement
}
else
echo "some error message here if you want..."

This way my code is way sorter and with just one variable it checks that the type matches at least one of the ones put into $checkall
 
Back
Top