Anonoymous Anonoymous - 3 months ago 9
PHP Question

PHP image validation not working

I am working on a CMS for my site. I've successfully created created the "new-post.php" page & added some conditions for image type & size validation. That works perfectly. I've the same page for updating the post. But the condition is not working on this page. It shows the "invalid image" alert even I upload an image with valid extension. What's wrong with my code?

Any help would be appreciated!

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>";
}

}

Answer

Typo error. It should be "image" not "pimage"

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")
Comments