Exemple #1
0
 /**
  * Returns the full path of the file.
  *
  * @return string Full path to the file
  */
 public function pwd()
 {
     if ($this->getPath() === null) {
         $dir = $this->Folder->pwd();
         if (is_dir($dir)) {
             return $this->Folder->slashTerm($dir) . $this->name;
         }
     }
     return $this->getPath();
 }
Exemple #2
0
 /**
  * Get the real path (taking ".." and such into account)
  *
  * @param string $path Path to resolve
  * @return string The resolved path
  */
 public function realpath($path)
 {
     $path = str_replace('/', DIRECTORY_SEPARATOR, trim($path));
     if (strpos($path, '..') === false) {
         if (!Folder::isAbsolute($path)) {
             $path = Folder::addPathElement($this->_path, $path);
         }
         return $path;
     }
     $parts = explode(DIRECTORY_SEPARATOR, $path);
     $newparts = [];
     $newpath = '';
     if ($path[0] === DIRECTORY_SEPARATOR) {
         $newpath = DIRECTORY_SEPARATOR;
     }
     while (($part = array_shift($parts)) !== null) {
         if ($part === '.' || $part === '') {
             continue;
         }
         if ($part === '..') {
             if (!empty($newparts)) {
                 array_pop($newparts);
                 continue;
             }
             return false;
         }
         $newparts[] = $part;
     }
     $newpath .= implode(DIRECTORY_SEPARATOR, $newparts);
     return Folder::slashTerm($newpath);
 }