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 7 of 7
  1. #1
    Senior Coder
    Join Date
    Feb 2003
    Location
    Ontario, Canada
    Posts
    1,223
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Verify the existance of a URL?

    I've got a field that takes a URL in the form of 'http://.../somefile.jpg' (without quotes) and I'd like to somehow check that the URL to the image they've provided returns an actual image file. Is there any other way to do this, other than fopen ($_POST['url'])? Even using fopen(), would I be able to assure that the file returned is actually a JPEG?

    Any suggestions would be greatly appreciated. In the meantime, I'll just allow broken URLs.

    Thanks,
    Aaron

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    I think fopen() ,file() or file_get_contents() etc is the quickest way , as to the mime-type there is no way you can check this until you have the file on your system (other than simply assuming the extension is correct!) as you can't perform file operations on remote files.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by AaronW
    I've got a field that takes a URL in the form of 'http://.../somefile.jpg' (without quotes) and I'd like to somehow check that the URL to the image they've provided returns an actual image file.

    If you mean a form field, check out these threads:


    http://www.codingforums.com/showthread.php?t=45398


    http://www.codingforums.com/showthread.php?t=45438


    -james
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    getimagesize()

    Exactly what you are looking for.
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)

  • #5
    Senior Coder
    Join Date
    Feb 2003
    Location
    Ontario, Canada
    Posts
    1,223
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ah! That's right! getimagesize () can do remote files. Sweet. Thanks

    Thanks to the others, too. And they aren't uploading the file, they're just typing a URL.

  • #6
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by AaronW
    Thanks to the others, too. And they aren't uploading the file, they're just typing a URL.
    Same difference.



    -james
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #7
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    Quote Originally Posted by ReadMe.txt
    getimagesize()

    Exactly what you are looking for.

    ok! well that shuts me up , well spotted
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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