PHP图像验证不起作用

时间:2016-08-08 10:27:36

标签: php file-upload pdo

我正在为我的网站开发CMS。我成功创建了“ new-post.php ”页面&为图像类型添加了一些条件&尺寸验证。这非常有效。我对更新帖子有相同的页面。但条件不适用于此页面。即使我上传了有效扩展名的图片,它也会显示“无效图片”提醒。我的代码出了什么问题?

任何帮助将不胜感激!

if(!$stmt)
            {
                echo "<div class='alert alert-danger' style='margin-top: 20px;'><span class='glyphicon glyphicon-exclamation-sign'></span> <strong>Post has not been updated.</strong></div><a href='dashboard?new' class='btn btn-danger btn-sm' style'margin-top: 50px;'>Take me there again.I'll try again.</a>";
            }
            else
            {
                if($image_type=="pimage/jpeg" OR $image_type=="pimage/jpg" OR $image_type=="pimage/png" OR $image_type=="pimage/bmp" OR $image_type=="pimage/gif")
                {
                    $stmt->execute();
                    move_uploaded_file($image_tmp, "uploads/$image");
                    echo "<div class='alert alert-success' style='margin-top: 20px;'><span class='glyphicon glyphicon-ok-sign'></span> <strong>Post has been updated successfully.</strong></div>
                        <a href='dashboard?view' class='btn btn-danger btn-lg' style'margin-top: 50px;'>Show me</a>";
                }
                else
                {
                    echo "<script>alert('Invalid image');</script>";
                }

            }

1 个答案:

答案 0 :(得分:0)

错字错误。它应该是&#34; image&#34;不是&#34; pimage&#34;

if($image_type=="image/jpeg" OR $image_type=="image/jpg" OR $image_type=="image/png" OR $image_type=="image/bmp" OR $image_type=="image/gif")