如果语句返回true

davelowe85

谁能告诉我为什么,选择一个PSD文件,if语句在PHP代码时通过真实与回声“图像/ 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>
强大的猪肉

因为这是错误的

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

应该

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

甚至

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

也就是说,因为非空字符串被视为true,所以满足了IF条件。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章