On 6 May 2002 at 20:30, Craig Westerman wrote: > File is on another server. Is there a way to check if file exists on > another server?
I wrote the following function a while ago to do this. It works with http URLs and should also work with https and ftp, but I have only tested http. I hope it's useful to you. function RemoteFileExists($url, $referer) { $url_parts = parse_url($url); if ($url_parts["scheme"] != "http" && $url_parts["scheme"] != "https" && $url_parts["scheme"] != "ftp") { // Don't currently handle shemes other than HTTP and HTTPS, so assume the file exists for now return TRUE; } $ch = curl_init(); $urltoget = $url_parts["scheme"]."://".$url_parts["host"].$url_parts["path"]; if (isset($url_parts["query"])) $urltoget .= "?".$urltoget["query"]; curl_setopt ($ch, CURLOPT_URL, $urltoget); if ($url_parts["scheme"] == "http" || $url_parts["scheme"] == "https") { curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_REFERER, $referer); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $reply = curl_exec($ch); curl_close($ch); if ($url_parts["scheme"] == "http" || $url_parts["scheme"] == "https") { $result = explode(" ", $reply); $reply = ($result[1] == "200"); } return $reply; } -- Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php