if statement returning true

php

Solution

Because this is wrong

if( $imagetype == "image/jpeg" || "image/gif" ) { /*...*/ }

Should be

if( $imagetype == "image/jpeg" || $imagetype == "image/gif" ) { /*...*/ }

Or even

if( in_array($imagetype, ["image/jpeg", "image/gif"]) ) { /*...*/ }

That is, because non-empty string is considered true, so the IF condition was met.

Problem

Can someone tell me why, when selecting a psd file, the if statement in the php code passes as true and echos "image/vnd.adobe.photoshop"? ``` <?php if (isset($_POST['submit'])) { foreach ($_FILES["myimages"]["error"] as $key => $error) { $tmp_name = $_FILES["myimages"]["tmp_name"][$key]; $name = $_FILES["myimages"]["name"][$key]; $imagetype = $_FILES['myimages']['type'][$key]; if ($imagetype == "image/jpeg" || "image/gif") { echo $imagetype; } } } ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <form method="post" enctype="multipart/form-data" action="<? echo basename(__file__); ?>"> <input type="file" name="myimages[]" multiple> <input name="submit" type="submit" value="submit"> </form> </body> </html> ```

Original source