예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function copy($originFile, $targetFile, $override = false)
 {
     if (!$this->has($originFile)) {
         throw new FileNotFoundException($originFile);
     }
     $orginal = $this->driver->applyPathPrefix($originFile);
     $target = $this->driver->applyPathPrefix($targetFile);
     // https://bugs.php.net/bug.php?id=64634
     if (@fopen($orginal, 'r') === false) {
         throw new ViserioIOException(sprintf('Failed to copy "%s" to "%s" because source file could not be opened for reading.', $orginal, $target), 0, null, $orginal);
     }
     // Stream context created to allow files overwrite when using FTP stream wrapper - disabled by default
     if (@fopen($target, 'w', false, stream_context_create(['ftp' => ['overwrite' => true]])) === false) {
         throw new ViserioIOException(sprintf('Failed to copy "%s" to "%s" because target file could not be opened for writing.', $orginal, $target), 0, null, $orginal);
     }
     $this->driver->copy($originFile, $targetFile);
     if (!is_file($target)) {
         throw new ViserioIOException(sprintf('Failed to copy "%s" to "%s".', $originFile, $target), 0, null, $originFile);
     }
     return true;
 }