有人可以告诉我为什么,当选择一个psd文件时,PHP代码中的if语句传递为true和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>
因为这是错误的
原文链接:https://www.f2er.com/php/135107.htmlif( $imagetype == "image/jpeg" || "image/gif" ) { /*...*/ }
应该
if( $imagetype == "image/jpeg" || $imagetype == "image/gif" ) { /*...*/ }
甚至
if( in_array($imagetype,["image/jpeg","image/gif"]) ) { /*...*/ }
也就是说,因为非空字符串被认为是真的,所以满足了IF条件.