Home » File System » File » Bug #7559
fileExists method
Details
| Request #7559 | fileExists method |
|---|---|
| Submitted | 2006-05-04 18:24 UTC |
| From | denny at php dot net |
| Assigned | mike |
| Status | Closed |
| Package | File |
| PHP Version | Irrelevant |
| OS | All |
| Roadmaps | 1.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;
}