I am trying to test if the uploaded file is the image type I want. If it isn’t a gif,jpeg, png, it should echo “Problem”. But when I execute this code, it always says there’s a problem. What’s wrong with my if statement?
$uploadfile_type=$_FILES['userfile']['type'];
if ( ($uploadfile_type !='image/gif') || ($uploadfile_type !='image/jpeg')
|| ($uploadfile_type !='image/png'))
{
echo 'Problem: file is not a gif or jpeg or png!';
exit;
}
This code works when I am only checking one type of image. Ex: if($uploadfile_type !=’image/gif’) –> this statement would work but when I add a OR it doesn’t.
You’re using OR (
||) when you should be using AND (&&). You want to say there’s a problem if it’s not a GIF and it’s not a JPG and it’s not a PNG. With OR, the only way it wouldn’t say there was a problem is if you had some sort of file that managed to be all 3 types at once.