Checking if image url exists

Hi there.

I just completed my first Object Oriented Programming class with an A- and I want to create my own program. The only problem I'm running into is how to program a function that checked to see if an image (.png, .jpg, or .gif) url exists online.

For example:

http://nonstickglue.net/button.gif is live and uploaded to my server; however http://nonstickglue.net/button1.gif is not.

If I have an array that stores both urls, I need the function to tell me which ones exist.

Hopefully that makes sense, if anyone has any guidance or wisdom I would greatly appreciate it.

-TJ
You could use a library such as libcurl, but that might be overkill if that's really all you need.
Instead, you could just connect to the server (using sockets), send a minimal HTTP request such as:
HEAD /button.gif HTTP/1.1
Host: nonstickglue.net


and then check the first line of the reply to see whether the server responded with 200 OK or 404 Not Found.
Last edited on
Topic archived. No new replies allowed.