PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » File System » File » Bug #7559

fileExists method

Details

Request #7559fileExists method
Submitted2006-05-04 18:24 UTC
Fromdenny at php dot net
Assignedmike
StatusClosed
PackageFile
PHP VersionIrrelevant
OSAll
Roadmaps1.3.0a1

Comments

[2006-05-04 18:24 UTC] denny at php dot net

Description:
------------
The following method checks for a file's existence, taking the current include path into consideration.

Test script:
---------------
/**
* Checks for a file's existence, taking the current include path into consideration
*
* This method can be called statically (e.g., File_Util::fileExists('config.php'))
*
* @param string $filename
* @param string $slash the directory separator (optional)
* @return false|string
* @access public
* @static
*/
function fileExists($filename, $slash = DIRECTORY_SEPARATOR)
{
$includePath = ini_get('include_path');
if ($paths = explode(PATH_SEPARATOR, $includePath)) {
foreach ($paths as $path) {
$file = "$path$slash$filename";
if (file_exists($file)) {
return $file;
}
}
}
return false;
}