meheler at canada dot com
07-Mar-2002 03:55
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