reply to both mail list and O.P.
- Original Message -
From: Stephen of Blank Canvas [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, January 18, 2003 08:42
Subject: [PHP] Does remote file(image) exist ?
Hi Everyone,
Sorry I have no example code at all for this at all, I know some people
don't like that but I just do not know where to start so am asking for
help.
I have a system there users can put a picture of themselves by method of
URL in a MySQL field, however many of this image URL's do not work as
users type them in wrong. So what I wanted to do was find a way to test
to see if the image can be accessed, then if not display a default
image.
Hope that makes sense, anyone already done something like this and want
to share code :-)
Stephen
Use curl,
or
write a script that executes a telnet session that issues
HEAD commands
The key command is the HEAD path-to-resource HTTP/1.0
Most servers are HTTP/1.1, but using 1.0 keeps backward compatibility.
The path-to-resource is whatever the path is that would appear after the
domain in the url.
You would want to split the submitted URL into domain and path.
You issue the telnet to $domain at port 80
telnet $domain 80
You issue the HEAD command
HEAD /path-to-resource HTTP/1.0
What follows is the servers response. I've included live
examples of both a 200 response (resource exists)
and a 404 response (resource does not exist).
Parse the responses and you will know that something
exists or not.
# telnet $domain 80
Trying {ip address}...
Connected to $domain
Escape character is '^]'.
HEAD /pov/box.png HTTP/1.0
HTTP/1.1 200 OK
Date: Sat, 18 Jan 2003 17:30:12 GMT
Server: Apache/1.3.27 (Unix) PHP/4.2.3
Last-Modified: Fri, 13 Dec 2002 23:29:56 GMT
ETag: 32e005-8c1d-3dfa6d74
Accept-Ranges: bytes
Content-Length: 35869
Connection: close
Content-Type: image/png
Connection closed by foreign host.
# telnet $domain 80
Trying {ip address}...
Connected to $domain
Escape character is '^]'.
HEAD /pov/box1.png HTTP/1.0
HTTP/1.1 404 Not Found
Date: Sat, 18 Jan 2003 17:30:58 GMT
Server: Apache/1.3.27 (Unix) PHP/4.2.3
Connection: close
Content-Type: text/html; charset=iso-8859-1
Connection closed by foreign host.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php