0

I got input in my website, The input is suppose to get image URL, What is want to validate is:

  1. Am i getting an image?
  2. Is it 64x64?
  3. Image type png/jpg/gif/etc?

The best solution for All the terms above i was thinking about is getimagesize.

If anyone can think of more terms for validating and better solution i will be very thankfull, Thank you all and have a nice day.

Aviel Fedida
  • 4,004
  • 9
  • 54
  • 88

2 Answers2

2

this is php code for checking format (say www.example.com/image.png)

$url = "some url";
$format = substr($url , -3);
if($format == "png" || $format == "jpg" || $format == "gif")
    print "right";
else
    print "wrong";
mamal
  • 69
  • 4
2

For the first ,

You could use getimagesize() which returns zeros for size on non-images.

For the second,

$imageName = $_FILES['upload']['name'];
list($width, $height, $type, $attr) = getimagesize($imageName);

you can check condition with $width and $height

For the third,

$imageName = $_FILES['upload']['name'];
$ext = pathinfo($imageName, PATHINFO_EXTENSION);// alternative method

You could use $type from second to check extention

With $ext you can check extention of image

Here is link for you http://www.phpeasystep.com/phptu/25.html

So in altogether you could simply use getimagesize() for these 3 conditions

Ajith S
  • 2,907
  • 1
  • 18
  • 30