note 19664 added to ref.filesystem
| From: | meheler at canada dot com | Date: | Thu, 07 Mar 2002 04:55:55 +0000 |
| Subject: | note 19664 added to ref.filesystem | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27451@lists.php.net to get a copy of this message | ||
Here is a useful function that checks for the existance of a file in PHP's include_path:
// Searches PHP's include_path variable for the existance of a file
// Returns the filename if it's found, otherwise FALSE.
// Only works on a *nix-based filesystem
// Check like: if (($file = file_exists_path('PEAR.php')) !== FALSE)
function file_exists_path($file) {
// Absolute path specified
if (substr($path,0,1)=='/')
return (file_exists($file))?realpath($file):FALSE;
$paths = explode(':',ini_get('include_path'));
foreach ($paths as $path) {
if (substr($path,-1)!='/') $path = "$path/";
if (file_exists("$path$file"))
return realpath("$path$file");
}
return FALSE;
}
Mike
--
http://www.php.net/manual/en/ref.filesystem.php
http://master.php.net/manage/user-notes.php?action=edit+19664
http://master.php.net/manage/user-notes.php?action=delete+19664
http://master.php.net/manage/user-notes.php?action=reject+19664