Jump to content

Checking if an image is an image


unkwntech

Recommended Posts

We used to pull this little trick with MySpace, we would insert an 'image' that was hosted on our servers ex: http://domain.tld/image.jpg however image.jpg would actually be a directory with a index.php that would print the users IP, user-agent and what not.

I would like to prevent this on my own projects so I'm wondering if there is an easy way to check if an external image is an image, without having to store it locally.

 

Edit: To clarify I don't want to check if the file is there but I want to check that the file is not a dir.

Link to comment
https://forums.phpfreaks.com/topic/115753-checking-if-an-image-is-an-image/
Share on other sites

Its difficult because the GD library in php can still produce an IMAGE but still process data based on the request (such as get the IP of the remote) address

 

Look at the thread below this about images I posted an is_img function that is fairly good.

 

http://www.phpfreaks.com/forums/index.php/topic,207782.0.html

We used to pull this little trick with MySpace, we would insert an 'image' that was hosted on our servers ex: http://domain.tld/image.jpg  however image.jpg would actually be a directory with a index.php that would print the users IP, user-agent and what not.

 

I think you'll find your directory was actually a php script (index.php) so your not looking to detect if the image is a directory but a php file producing an image. Unfortunately, there is no difference in the end. As long as the php file sends the correct headers, it is an image, just as browsers think php pages are html.

What is_img function? Its easy enough to find out if something is an image by using getimagesize which will return false if the file provided isn't an image. However, as I said in my last post, as long as the php script in question sends the appropriate headers it is an image.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.