note 59985 deleted from function.file-exists by nlopess

From: Date: Thu, 22 Dec 2005 12:14:23 +0000
Subject: note 59985 deleted from function.file-exists by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-100566@lists.php.net to get a copy of this message
Note Submitter: Fabrizio (staff at bibivu dot com) ---- here a function to check if a certain URL exist: function url_exists($url) { $a_url = parse_url($url); if (!isset($a_url['port'])) $a_url['port'] = 80; $errno = 0; $errstr = ''; $timeout = 30; if(isset($a_url['host']) && $a_url['host']!=gethostbyname($a_url['host'])){ $fid = fsockopen($a_url['host'], $a_url['port'], $errno, $errstr, $timeout); if (!$fid) return false; $page = isset($a_url['path']) ?$a_url['path']:''; $page .= isset($a_url['query'])?'?'.$a_url['query']:''; fputs($fid, 'HEAD '.$page.' HTTP/1.0'."\r\n".'Host: '.$a_url['host']."\r\n\r\n"); $head = fread($fid, 4096); fclose($fid); return preg_match('#^HTTP/.*\s+[200|302]+\s#i', $head); } else { return false; } } in my CMS, I am using it with those lines: if(!isset($this->f_exist[$image]['exist'])) if(strtolower(substr($fimage,0,4)) == 'http' || strtolower(substr($fimage,0,4)) == 'www.'){ if(strtolower(substr($image,0,4)) == 'www.'){ $fimage = 'http://'.$fimage; $image = 'http://'.$image; } $this->f_exist[$image]['exist'] = $this->url_exists($fimage); //for now } else { $this->f_exist[$image]['exist'] = ($fimage!='' && file_exists($fimage) && is_file($fimage) && is_readable($fimage) && filesize($fimage)>0); } }

« previous php.notes (#100566) next »