Checking Upload File Type Not Working

I’m trying to check and make sure that the file type being uploaded is gif, png, jpg, or jpeg.

I have this:
[php]
$type = $_FILES[‘uploaded’][‘type’];
if ($type != “image/png”) {
echo “File type not supported.”;
}

else {
//upload
}
[/php]

It works fine because I’ll upload a png and it goes through and when i try to upload something else it doesn’t

But when I try to do this:
[php]
if ($type != “image/png” || $type != “image/jpeg” || $type != “image/jpg” || $type != “image/gif”) {
[/php]

It doesn’t work for anything. What am I doing wrong?

Well think about your logic using OR

If you have an image/png then it does not equal image/jpeg or image/jpg or image/gif so the condition is true

I think what you meant to do was AND

[php]if ($type != “image/png” && $type != “image/jpeg” && $type != “image/jpg” && $type != “image/gif”) {[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service