Image extension proper validation

by mariganesh 2014-03-20 13:14:19

Image extension validation using by mime

Image extension validation using by mime in php . it can be used to avoid upload unwanted images and files.so it is more secure.



<?php
$tmpname1 = $_FILES["myfile"]["tmp_name"]; // uploading image tmpname or image name
$details=getimagesize($tmpname1);
if($details['mime']!="")
{
$filename = pathinfo($_FILES['myfile']['name']);
$file = strtolower($filename['extension']);
$fsize=($_FILES["myfile"]["size"] / 1024);
list($w, $h) = getimagesize($_FILES["myfile"]["tmp_name"]);
if (($details['mime'] == "image/png") || ($details['mime'] == "image/jpeg") || ($details['mime'] == "image/gif"))
{
echo "sucess";
}
else
{
echo "Invalid Exension";
}
}
else
{
echo "Invalid Exension";
}
?>



1056
like
0
dislike
0
mail
flag

You must LOGIN to add comments