note 76473 added to function.file-exists
| From: | openspecies at osu1 dot php dot net | Date: | Tue, 17 Jul 2007 13:21:09 +0000 |
| Subject: | note 76473 added to function.file-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128652@lists.php.net to get a copy of this message | ||
/*
* EXTERN/FS FILE
* a simple alternative without cURL
*/
function sys_file_exists($f = NULL)
{
$h = array();
$ret = FALSE;
if(!is_null($f)):
if(preg_match('/^http|https|ftp/',$f)): //test protocol EXTERN
$h = @get_headers($f);
if(array_key_exists(0,$h)) :
$ret = (bool) preg_match('/200|301/',$h[0]); /* HTTP/1.1 301 DAP (directory) */
endif;
else: //else FS
$ret = (file_exists($f) && is_readable($f));
endif;
endif;
return (($ret === TRUE) ? TRUE : FALSE);
}
then, it's easy to replace file_exists in your code,
grep -R file_exists path/to/frameworks
...
private function _loadModel($file = NULL)
{
//TRACE($file);
try {
if(is_null($file) || !sys_file_exists($file)) :
throw new SF_websiteview_exception('loadModel : '.$file.' could not be
loaded');
endif;
} catch(SF_websiteview_exception $ex){$ex->trace(FALSE);}
return file_get_contents($file);
}
...
private function _loadtable($file)
{
try {
if(sys_file_exists($file)):
$buf = file($file);
else:
throw new SF_localization_exception('Table '.$this->tablename.' could not be
loaded');
endif;
} catch(SF_localization_exception $ex){$ex->trace(TRUE);$ex->__exit();}
$tbl = array();
$i = 0;
while ($i < count($buf) ) :
if (preg_match('/"(.*)"+[ = ]+"(.*)";+$/',trim($buf[$i]),$row)
&& !preg_match("/^[\/\/|\/\*]/",$buf[$i])) :
$tbl[$row[1]] = $row[2];
endif;
$i++;
endwhile;
$this->table = $tbl;
unset($tbl,$buf);
}
...
@+
----
Server IP: 194.145.210.3
Probable Submitter: 80.169.153.20
----
Manual Page -- http://www.php.net/manual/en/function.file-exists.php
Edit -- https://master.php.net/note/edit/76473
Del: integrated -- https://master.php.net/note/delete/76473/integrated
Del: useless -- https://master.php.net/note/delete/76473/useless
Del: bad code -- https://master.php.net/note/delete/76473/bad+code
Del: spam -- https://master.php.net/note/delete/76473/spam
Del: non-english -- https://master.php.net/note/delete/76473/non-english
Del: in docs -- https://master.php.net/note/delete/76473/in+docs
Del: other reasons-- https://master.php.net/note/delete/76473
Reject -- https://master.php.net/note/reject/76473
Search -- https://master.php.net/manage/user-notes.php