Example #1
0
 /**
  *
  * Creates a new temporary file.
  *
  * @return \Mbcraft\Piol\File The new temporary file instance.
  *
  * @api
  */
 public static function newTempFile()
 {
     $full_path = tempnam(Dir::asDir(self::$tmp_file_path)->getFullPath(), "tmp_");
     return new File(File::toRelativePath($full_path));
 }
Example #2
0
 /**
  * 
  * Saves the uploaded file into the specified folder optionally overriding the filename used during upload.
  * The temporary upload file is deleted.
  * 
  * @param \Mbcraft\Piol\Dir|string $dir The Dir instance or string path of the folder in which save the uploaded file.
  * @param string $new_name the optional name to use for the file (overrides upload filename).
  * @return \Mbcraft\Piol\File a File instance pointing to the saved file, or null if an error occurred.
  *
  * @throws \Mbcraft\Piol\IOException if something goes wrong (eg. the provided filename is not valid).
  * 
  * @api
  */
 public function moveTo($dir, $new_name = null)
 {
     $final_dir = Dir::asDir($dir);
     FileSystemUtils::checkValidFilename($new_name);
     if ($new_name == null) {
         $real_filename = $this->getFullName();
     } else {
         $real_filename = $new_name;
     }
     $final_file = $final_dir->newFile($real_filename);
     return $this->saveAs($final_file);
 }
Example #3
0
File: Dir.php Project: mbcraft/piol
 /**
  * 
  * Sets the permissions on this directory using a 9 [rwx-] character string.
  * This operation is not guaranteed to succeed.
  * 
  * @param string $rwx_permissions The string permissions to set for this directory. 
  * @param boolean $recursive defaults to false, sets the permissions to all the child file system elements.
  * @return boolean true if the operation was succesfull, false otherwise.
  * 
  * @api
  */
 public function setPermissions($rwx_permissions, $recursive = false)
 {
     $result = $this->setPermissionsRwx($rwx_permissions);
     if ($recursive) {
         foreach ($this->listFolders() as $folder) {
             $rr = Dir::asDir($folder)->setPermissions($rwx_permissions, $recursive);
             $result &= $rr;
         }
         foreach ($this->listFiles() as $file) {
             $rr = File::asFile($file)->setPermissionsRwx($rwx_permissions);
             $result &= $rr;
         }
     }
     return $result;
 }
Example #4
0
 /**
  * 
  * Returns the relative path of this element.
  * 
  * @param \Mbcraft\Piol\Dir|string $ancestor An optional ancestor Dir or string path for returning a shortened path.
  * @return string The string path
  * @throws \Mbcraft\Piol\IOException If the ancestor path is not a prefix of the relative path.
  * 
  * @api
  */
 public function getPath($ancestor = null)
 {
     if ($ancestor == null) {
         return $this->__path;
     } else {
         $relative_dir = Dir::asDir($ancestor);
         $path = $relative_dir->getPath();
         if (strpos($this->__path, $path) === 0) {
             return DS . substr($this->__path, strlen($path));
         } else {
             throw new IOException("Il percorso non comincia col percorso specificato : " . $this->__path . " non comincia con " . $path);
         }
     }
 }