note 19266 added to function.file-exists

From: Date: Thu, 21 Feb 2002 14:55:19 +0000
Subject: note 19266 added to function.file-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-26888@lists.php.net to get a copy of this message
To check if a file on the internet exists, in some cases the fopen() won't work, because the webserver may return an error 404 page, so fopen returns true. To avoid this i wrote a function: function urlExists($url) { $url = ereg_replace("http://", "", $url); list($domain, $file) = explode("/", $url, 2); $fid=fsockopen($domain,80); fputs($fid,"GET /$file HTTP/1.0\r\nHost: $domain\r\n\r\n"); $gets = fgets($fid, 1024); fclose($fid); if (ereg("HTTP/1.1 200 OK", $gets)) return TRUE; else return FALSE; } -- http://www.php.net/manual/en/function.file-exists.php http://master.php.net/manage/user-notes.php?action=edit+19266 http://master.php.net/manage/user-notes.php?action=delete+19266 http://master.php.net/manage/user-notes.php?action=reject+19266

« previous php.notes (#26888) next »