/** * * Copies this directory and all its content to a new path. * * @param \Mbcraft\Piol\Dir|string $path the path where to copy this folder and all its content. * @param string $new_name An aoptional new name for the copied folder. * * @api */ public function copy($path, $new_name = null) { $target_dir = Dir::asDir($path); if ($new_name == null) { $new_name = $this->getName(); } else { FileSystemUtils::checkValidFilename($new_name); } $copy_dir = $target_dir->newSubdir($new_name); $results = $this->listElements(Dir::MODE_FILES_AND_FOLDERS); $all_elements = array_merge($results[0], $results[1]); foreach ($all_elements as $elem) { $elem->copy($copy_dir); } }
/** * * Copies this file to the target folder. * * @param \Mbcraft\Piol\Dir|string $target_dir The target dir or string path to copy this file into. * @param string $new_name An optional new name for the copied file. * @return boolean true if this operation was successfull, false otherwise. * * @api */ public function copy($target_dir, $new_name = null) { $t_dir = Dir::asDir($target_dir); if ($new_name == null) { $n_name = $this->getFullName(); } else { FileSystemUtils::checkValidFilename($new_name); $n_name = $new_name; } return copy($this->__full_path, $t_dir->__full_path . $n_name); }
/** * * 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); }