...

View Full Version : is URL an image?



jasonc310771
08-13-2008, 11:35 AM
How can i find out if a URL is an image?

ok say i have a link submitted and it is a direct link (yes a hot link!) to an image how can i find this out as the url is not always ending in .jpg or .jpeg or someother image ext.

some links that i know are ok are like this...

www.site.com/img1.jpg
www.site.com/img1.png

but if a url is..
www.site.com/img1.jpg?v=0

then my script can not work this out. and create a thumb nail from the image for my home page, i have to manually check each one and set it if it is an image. if not an image then it does not show any thumbnail.

is there another way to test?

thanks in advance for your help.

mlse
08-13-2008, 12:02 PM
Have a look at the parse_url (http://uk3.php.net/manual/en/function.parse-url.php) function - that should help you :)

For example, the following code prints "jpg":


$url = "http://www.mydomain.com/page.jpg?x=0&y=1";
echo pathinfo(parse_url($url, PHP_URL_PATH), PATHINFO_EXTENSION)."\n";


Also check out mime_content_type (http://uk3.php.net/manual/en/function.mime-content-type.php) (although this has been deprecated - see the notes for the fuction) and the Fileinfo (http://uk3.php.net/manual/en/ref.fileinfo.php) extension that supercedes it.

I hope that helps!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum