Example #1
0
 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;
 }