Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    478
    Thanks
    3
    Thanked 0 Times in 0 Posts

    is URL an image?

    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.

  • #2
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Have a look at the parse_url function - that should help you

    For example, the following code prints "jpg":
    PHP Code:
    $url "http://www.mydomain.com/page.jpg?x=0&y=1";
    echo 
    pathinfo(parse_url($urlPHP_URL_PATH), PATHINFO_EXTENSION)."\n"
    Also check out mime_content_type (although this has been deprecated - see the notes for the fuction) and the Fileinfo extension that supercedes it.

    I hope that helps!
    Last edited by mlse; 08-13-2008 at 11:11 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •