Esempio n. 1
0
File: get.php Progetto: Borvik/Munla
 /**
  * Attempts to get the file path of the given directory (as relative to the URL).
  * 
  * @param string $file The relative path of the directory to find.
  * 
  * @return string|bool Returns the path to the local directory, or boolean FALSE on failure.
  */
 public static function cache_dir_path($file)
 {
     $docroot = strtr($_SERVER['DOCUMENT_ROOT'], '\\', '/');
     $self = strtr($_SERVER['PHP_SELF'], '\\', '/');
     if (substr($docroot, -1) != '/') {
         $docroot .= '/';
     }
     if (substr($self, 0, 1) == '/') {
         $self = substr($self, 1);
     }
     $base_dir = get::dirname($docroot . $self);
     if (substr($base_dir, -1) != '/') {
         $base_dir .= '/';
     }
     if (strlen($file) > strlen($docroot) && strtolower(substr($file, 0, strlen($docroot))) == strtolower($docroot)) {
         $file = substr($file, strlen($docroot));
     }
     //try relative (from basename of URL file, and server docroot)
     if (file_exists($base_dir . $file) && is_dir($base_dir . $file)) {
         $path = get::realpath($base_dir . $file);
         if ($path !== false && strtolower(substr($path, 0, strlen($docroot))) == strtolower($docroot)) {
             //file is within the website
             return $path;
         }
     }
     if (file_exists($docroot . $file) && is_dir($docroot . $file)) {
         $path = get::realpath($docroot . $file);
         if ($path !== false && strtolower(substr($path, 0, strlen($docroot))) == strtolower($docroot)) {
             //file is within the website
             return $path;
         }
     }
     //file is outside of the website - hacking attempt (or doesn't exist)
     return false;
 }