- /**
- * Checks whether the given file/path is in open_basedir(). This does not
- * gurantee that the file is actually readable and/or writeable. If you need
- * such gurantee then please use isReadableFile() instead.
- *
- * @param $filePathName Name of the file/path to be checked
- * @return $isReachable Whether it is within open_basedir()
- */
- protected static function isReachableFilePath ($filePathName) {
- // Is not reachable by default
- $isReachable = FALSE;
-
- // Get open_basedir parameter
- $openBaseDir = ini_get('open_basedir');
-
- // Is it set?
- if (!empty($openBaseDir)) {
- // Check all entries
- foreach (explode(PATH_SEPARATOR, $openBaseDir) as $dir) {
- // Check on existence
- if (substr($filePathName, 0, strlen($dir)) == $dir) {
- // Is reachable
- $isReachable = TRUE;
- } // END - if
- } // END - foreach
- } else {
- // If open_basedir is not set, all is allowed
- $isReachable = TRUE;
- }
-
- // Return status
- return $isReachable;
- }
-
- /**
- * Checks whether the give file is within open_basedir() (done by
- * isReachableFilePath()), is actually a file and is readable.
- *
- * @param $fileName Name of the file to be checked
- * @return $isReadable Whether the file is readable (and therefor exists)
- */
- public static function isReadableFile ($fileName) {
- // Default is not readable
- $isReadable = FALSE;
-
- // Is within parameters, so check if it is a file and readable
- $isReadable = ((self::isReachableFilePath($fileName)) && (file_exists($fileName)) && (is_file($fileName)) && (is_readable($fileName)));
-
- // Return status
- return $isReadable;
- }
-