logical operators...

[php]$allowed_extensions = array(“application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”, “application/vnd.ms-excel”);

if( ( $_FILES[‘ppm’][‘type’] != $allowed_extensions[0] || $_FILES[‘ppm’][‘type’] != $allowed_extension[1]) )
{
echo “Bad file type”;
exit();
}[/php]

the above code is basically supposed to get the file type of the file uploaded to the form and compare it to both elements in the array. The files needs to be either xls or xlsx format so if it isn’t in either xls or xlsx it echos bad file type and exit out of php code and doesn’t do the rest of the code… I hope what I’ve said makes since , however I know I’m bad at explaining things … but I do appreciate the help.

oh and by the way, the code itself works when its just one conditional in the if statment, however when I throw the logical || in there, it doesn’t work. I need it to execute that code when either values in the if statement are false… gah i hope this makes since…

never mind I solved my own issue, I just nested the if statements

[php] if( $_FILES[‘ppm’][‘type’] !+ $allowed_extensions[0] )

Thanks for posting the fix, I have run into that before and I usually just give up!

Well the correct fix is to see how the condition was failing and using a proper evaluation of the conidtional
[php]
$a=2;
if($a != 1 || $a !=2)
echo ‘error’;
else
echo ‘ok’;
[/php]

The reason this evaluation fails, is because $a never passes the first comparison, so goes to an error message. The only time it makes a comparison of the second conditional is when the first conditional is true.
It’s a common mistake. So how to fix it?

[php]
if(!($a == 1 || $a ==2))
echo ‘error’;
else
echo ‘ok’;
[/php]

by checking all conditionals before applying the not :slight_smile:
so $a, even tho it fails the first conditional ==1, it will drop to the 2nd conditional ==2, which will pass.
Returning a TRUE result, than inverted with NOT (FALSE now) so failing the first conditional, going to the else statement :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service