public function copy($destination, $overwrite = false, $mt = false) { // if (dirname($destination) == ".") { // $destination = $this->getDirectory() . DS . $destination; // } $destination = $this->preparePath($destination); if (strcmp(substr($destination, -1), DS) == 0) { $destination .= $this->getName(); } $file = new File($destination); $dir = new Directory($file->getDirectory()); if (!$dir->exists() && !$dir->make()) { throw new FileException(array("Directory '%s' not exists.", $dir->getPath())); } if (!$overwrite && $file->exists()) { throw new FileException(array("File '%s' already exists.", $file->getPath())); } if ($file->exists() && !$file->delete()) { throw new FileException(array("File '%s' cannot be deleted.", $file->getPath())); } if (!copy($this->pathAbsolute, $file->getPathAbsolute())) { throw new FileException(array("Failed to copy file '%s'.", $this->path)); } if ($mt) { $filemtime = $this->getModificationTime(); @touch($file->getPathAbsolute(), $filemtime); } return $file; }
function execute() { $file_or_folder = $this->file_or_folder; if (self::$dummy_mode) { echo "Adding : " . $file_or_folder . "<br />"; return; } $root_dir_path = self::$root_dir->getPath(); $file_or_folder = str_replace("\\", "/", $file_or_folder); $file_list = array(); //se finisce con lo slash รจ una directory if (substr($file_or_folder, strlen($file_or_folder) - 1, 1) == "/") { //creo la cartella $target_dir = new Dir(DS . $root_dir_path . $file_or_folder); $target_dir->touch(); $source_dir = new Dir($this->module_dir->getPath() . $file_or_folder); foreach ($source_dir->listFiles() as $elem) { if ($elem->isDir()) { $file_list = array_merge($file_list, $this->add($file_or_folder . $elem->getName() . DS)); } else { $file_list = array_merge($file_list, $this->add($file_or_folder . $elem->getFilename())); } } } else { $source_file = new File($this->module_dir->getPath() . $file_or_folder); $target_file = new File($root_dir_path . $file_or_folder); $target_dir = $target_file->getDirectory(); $target_dir->touch(); $source_file->copy($target_dir); $file_list[] = $target_dir->newFile($source_file->getFilename())->getPath(); } return $file_list; }
static function delete_image_thumbnails($path) { if ($path instanceof File) { $image_file = $path; } else { $image_file = new File($path); } $image_dir = $image_file->getDirectory(); $full_cache_dir = new Dir(self::THUMBNAILS_DIR . $image_dir->getPath()); $folders = $full_cache_dir->listFolders(); foreach ($folders as $f) { $image_thumb = $f->newFile($image_file->getFilename()); if ($image_thumb->exists()) { $image_thumb->delete(); } if ($f->isEmpty()) { $f->delete(); } } if ($full_cache_dir->isEmpty()) { $full_cache_dir->delete(); } }