public function paste($volume, $src, $dst, $rmSrc = false)
{
$err = $rmSrc ? elFinder::ERROR_MOVE : elFinder::ERROR_COPY;
if ($this->commandDisabled('paste')) {
return $this->setError($err, '#' . $src, elFinder::ERROR_PERM_DENIED);
}
if (($file = $volume->file($src, $rmSrc)) == false) {
return $this->setError($err, '#' . $src, elFinder::ERROR_FILE_NOT_FOUND);
}
$name = $file['name'];
$errpath = $volume->path($src);
if (($dir = $this->dir($dst)) == false) {
return $this->setError($err, $errpath, elFinder::ERROR_TRGDIR_NOT_FOUND, '#' . $dst);
}
if (!$dir['write'] || !$file['read']) {
return $this->setError($err, $errpath, elFinder::ERROR_PERM_DENIED);
}
$destination = $this->decode($dst);
if ($test = $volume->closest($src, $rmSrc ? 'locked' : 'read', $rmSrc)) {
return $rmSrc ? $this->setError($err, $errpath, elFinder::ERROR_LOCKED, $volume->path($test)) : $this->setError($err, $errpath, elFinder::ERROR_PERM_DENIED);
}
$test = $this->_joinPath($destination, $name);
$stat = $this->stat($test);
$this->clearcache();
if ($stat) {
if ($this->options['copyOverwrite']) {
// do not replace file with dir or dir with file
if (!$this->isSameType($file['mime'], $stat['mime'])) {
return $this->setError(elFinder::ERROR_NOT_REPLACE, $this->_path($test));
}
// existed file is not writable
if (!$stat['write']) {
return $this->setError($err, $errpath, elFinder::ERROR_PERM_DENIED);
}
// existed file locked or has locked child
if ($locked = $this->closestByAttr($test, 'locked', true)) {
return $this->setError(elFinder::ERROR_LOCKED, $this->_path($locked));
}
// target is entity file of alias
if ($volume == $this && ($test == @$file['target'] || $test == $this->decode($src))) {
return $this->setError(elFinder::ERROR_REPLACE, $errpath);
}
// remove existed file
if (!$this->remove($test)) {
return $this->setError(elFinder::ERROR_REPLACE, $this->_path($test));
}
} else {
$name = $this->uniqueName($destination, $name, ' ', false);
}
}
// copy/move inside current volume
if ($volume == $this) {
$source = $this->decode($src);
// do not copy into itself
if ($this->_inpath($destination, $source)) {
return $this->setError(elFinder::ERROR_COPY_INTO_ITSELF, $errpath);
}
$method = $rmSrc ? 'move' : 'copy';
return ($path = $this->{$method}($source, $destination, $name)) ? $this->stat($path) : false;
}
// copy/move from another volume
if (!$this->options['copyTo'] || !$volume->copyFromAllowed()) {
return $this->setError(elFinder::ERROR_COPY, $errpath, elFinder::ERROR_PERM_DENIED);
}
if (($path = $this->copyFrom($volume, $src, $destination, $name)) == false) {
return false;
}
if ($rmSrc) {
if ($volume->rm($src)) {
$this->removed[] = $file;
} else {
return $this->setError(elFinder::ERROR_MOVE, $errpath, elFinder::ERROR_RM_SRC);
}
}
return $this->stat($path);
}