Forum Moderators: coopster

Message Too Old, No Replies

Help with bolean value in if statement

An other way to write this "hell" statement

         

tomda

11:33 am on Nov 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would like to check if my file_type is different than jpeg or pjpeg.

Example :
//****************
$type="image/jpeg";
if ($type!="image/jpeg" ¦¦ $type!="image/pjpeg") {echo "error";}
//*****************
This example will always return an error despite the filename is correct. What would be the statement so that it returns an error ONLY if both doesn't match.

The alternative I have is this one...
// **************
if ($type=="image/jpeg" ¦¦ $type=="image/pjpeg") {} else {
$preview="error";}
//***************
... but this is not what I need (because I have a long list of elseif statements)

Hope I was clear... Any help?
Thanks

mincklerstraat

12:06 pm on Nov 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




$type="image/jpeg";
if ($type!="image/jpeg" && $type!="image/pjpeg") {echo "error";}

¦¦
= 'OR'; (note: pipes need to be repaired to non-broken pipes);
&&
= 'AND';

[be2.php.net...]

happy coding!

pete_m

12:16 pm on Nov 9, 2004 (gmt 0)

10+ Year Member



Alternatively...

$type="image/jpeg";

switch ($type) {

case "image/jpeg":
case "image/pjpeg":
//OK
break;

default:
echo("error");
}

dreamcatcher

6:26 pm on Nov 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



heres another alternative too.

$type = "image/jpeg";

$extensions = array("image/jpeg", "image/pjpeg");

if (!in_array($type, $extensions))
{
echo "Error";
}

All do basically the same thing. :)