: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
return $this->setError(elFinder::ERROR_UPLOAD_FILE_SIZE);
$dstpath = $this->decode($dst);
if (isset($hashes[$name])) {
$test = $this->decode($hashes[$name]);
$file = $this->stat($test);
$test = $this->joinPathCE($dstpath, $name);
$file = $this->isNameExists($test);
if ($file && $file['name'] === $name) { // file exists and check filename for item ID based filesystem
if ($this->uploadOverwrite) {
return $this->setError(elFinder::ERROR_PERM_DENIED);
} elseif ($file['mime'] == 'directory') {
return $this->setError(elFinder::ERROR_NOT_REPLACE, $name);
$name = $this->uniqueName($dstpath, $name, '-', false);
if (strpos($mime, 'image') === 0 && ($s = getimagesize($tmpname))) {
if (($path = $this->saveCE($fp, $dstpath, $name, $stat)) == false) {
$stat = $this->stat($path);
if (empty($stat['url']) && ($url = $this->getContentUrl($stat['hash']))) {
* @param Object $volume source volume
* @param string $dst destination dir hash
* @param bool $rmSrc remove source after copy?
* @throws elFinderAbortException
* @internal param string $source file hash
* @author Dmitry (dio) Levashov
public function paste($volume, $src, $dst, $rmSrc = false, $hashes = array())
$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);
$errpath = $volume->path($file['hash']);
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))) {
? $this->setError($err, $errpath, elFinder::ERROR_LOCKED, $volume->path($test))
: $this->setError($err, $errpath, empty($file['thash']) ? elFinder::ERROR_PERM_DENIED : elFinder::ERROR_MKOUTLINK);
if (isset($hashes[$name])) {
$test = $this->decode($hashes[$name]);
$stat = $this->stat($test);
$test = $this->joinPathCE($destination, $name);
$stat = $this->isNameExists($test);
if ($stat && $stat['name'] === $name) { // file exists and check filename for item ID based filesystem
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($stat['hash']));
// existed file is not writable
if (empty($stat['write'])) {
return $this->setError($err, $errpath, elFinder::ERROR_PERM_DENIED);
if ($this->options['copyJoin']) {
if (!empty($stat['locked'])) {
return $this->setError(elFinder::ERROR_LOCKED, $this->path($stat['hash']));
// existed file locked or has locked child
if (($locked = $this->closestByAttr($test, 'locked', true))) {
$stat = $this->stat($locked);
return $this->setError(elFinder::ERROR_LOCKED, $this->path($stat['hash']));
// target is entity file of alias
if ($volume === $this && ((isset($file['target']) && $test == $file['target']) || $test == $this->decode($src))) {
return $this->setError(elFinder::ERROR_REPLACE, $errpath);
if (!$this->options['copyJoin'] || $stat['mime'] !== 'directory') {
if (!$this->remove($test)) {
return $this->setError(elFinder::ERROR_REPLACE, $this->path($stat['hash']));
} else if ($stat['mime'] === 'directory') {
$name = $this->uniqueName($destination, $name, ' ', false);
// copy/move inside current volume
if ($volume === $this) { // changing == operand to === fixes issue #1285 - Paul Canning 24/03/2016
$source = $this->decode($src);
// do not copy into itself
if ($this->inpathCE($destination, $source)) {
return $this->setError(elFinder::ERROR_COPY_ITSELF, $errpath);
if ($res = ($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) {
if ($rmSrc && !$this->error()) {
if (!$volume->rm($src)) {
if ($volume->file($src)) {
$this->addError(elFinder::ERROR_RM_SRC);
$this->removed[] = $file;
$res = $this->stat($path);
* Return path info array to archive of target items
public function zipdl($hashes)
if ($this->commandDisabled('zipdl')) {
return $this->setError(elFinder::ERROR_PERM_DENIED);
$archivers = $this->getArchivers();
if (!$archivers || empty($archivers['create'])) {
$archivers = $archivers['create'];
foreach (array('zip', 'tgz') as $ext) {
$mime = $this->mimetype('file.' . $ext, true);
if (isset($archivers[$mime])) {
$cmd = $archivers[$mime];
$cmd = array_shift($archivers);
$mime = $this->mimetype('file.' . $ext, true);
$hashes = array_values($hashes);
$dirname = dirname(str_replace($this->separator, DIRECTORY_SEPARATOR, $this->path($hashes[0])));
for ($i = 1; $i < $cnt; $i++) {
if ($dirname !== dirname(str_replace($this->separator, DIRECTORY_SEPARATOR, $this->path($hashes[$i])))) {
if ($mixed || $this->root == $this->dirnameCE($this->decode($hashes[0]))) {
$prefix = $this->rootName;
$prefix = basename($dirname);
if ($dir = $this->getItemsInHand($hashes)) {
$tmppre = (substr(PHP_OS, 0, 3) === 'WIN') ? 'zd-' : 'elfzdl-';
// garbage collection (expire 2h)
register_shutdown_function(array('elFinder', 'GlobGC'), $pdir . DIRECTORY_SEPARATOR . $tmppre . '*', 7200);
$files = self::localScandir($dir);
if ($files && ($arc = tempnam($dir, $tmppre))) {
$arc = $arc . '.' . $ext;
if ($arc = $this->makeArchive($dir, $files, $name, $cmd)) {
$file = tempnam($pdir, $tmppre);
$res = rename($arc, $file);
$this->rmdirRecursive($dir);
return $res ? array('path' => $file, 'ext' => $ext, 'mime' => $mime, 'prefix' => $prefix) : false;
* @param string $hash file hash
* @author Dmitry (dio) Levashov
public function getContents($hash)
$file = $this->file($hash);
return $this->setError(elFinder::ERROR_FILE_NOT_FOUND);
if ($file['mime'] == 'directory') {
return $this->setError(elFinder::ERROR_NOT_FILE);
return $this->setError(elFinder::ERROR_PERM_DENIED);
if ($this->getMaxSize > 0 && $file['size'] > $this->getMaxSize) {
return $this->setError(elFinder::ERROR_UPLOAD_FILE_SIZE);
return $file['size'] ? $this->_getContents($this->convEncIn($this->decode($hash), true)) : '';
* Put content in text file and return file info.
* @param string $hash file hash
* @param string $content new file content
* @author Dmitry (dio) Levashov
public function putContents($hash, $content)
if ($this->commandDisabled('edit')) {
return $this->setError(elFinder::ERROR_PERM_DENIED);
$path = $this->decode($hash);
if (!($file = $this->file($hash))) {
return $this->setError(elFinder::ERROR_FILE_NOT_FOUND);
return $this->setError(elFinder::ERROR_PERM_DENIED);
if (preg_match('~^\0data:(.+?/.+?);base64,~', $content, $m)) {
if ($file['size'] > 0 && $dMime !== $file['mime']) {
return $this->setError(elFinder::ERROR_PERM_DENIED);
$content = base64_decode(substr($content, strlen($m[0])));
$name = $this->basenameCE($path);
$mimeByName = $this->mimetype($name, true);
if ($this->mimeDetect !== 'internal') {
if ($tp = $this->tmpfile()) {
$info = stream_get_meta_data($tp);
$filepath = $info['uri'];
$mime = $this->mimetype($filepath, $name);
if (!$this->allowPutMime($mimeByName) || ($mime && !$this->allowPutMime($mime))) {
return $this->setError(elFinder::ERROR_UPLOAD_FILE_MIME);
if ($this->convEncOut($this->_filePutContents($this->convEncIn($path), $content))) {
$res = $this->stat($path);
* Extract files from archive
* @param string $hash archive hash
* @author Dmitry (dio) Levashov,
* @author Alexey Sukhotin
public function extract($hash, $makedir = null)
if ($this->commandDisabled('extract')) {
return $this->setError(elFinder::ERROR_PERM_DENIED);
if (($file = $this->file($hash)) == false) {
return $this->setError(elFinder::ERROR_FILE_NOT_FOUND);
$archiver = isset($this->archivers['extract'][$file['mime']])
? $this->archivers['extract'][$file['mime']]
return $this->setError(elFinder::ERROR_NOT_ARCHIVE);
$path = $this->decode($hash);
$parent = $this->stat($this->dirnameCE($path));
if (!$file['read'] || !$parent['write']) {
return $this->setError(elFinder::ERROR_PERM_DENIED);
$this->extractToNewdir = is_null($makedir) ? 'auto' : (bool)$makedir;
if ($path = $this->convEncOut($this->_extract($this->convEncIn($path), $archiver))) {
foreach ($path as $_k => $_p) {
$path[$_k] = $this->stat($_p);
$path = $this->stat($path);
public function archive($hashes, $mime, $name = '')
if ($this->commandDisabled('archive')) {
return $this->setError(elFinder::ERROR_PERM_DENIED);
if ($name !== '' && !$this->nameAccepted($name, false)) {
return $this->setError(elFinder::ERROR_INVALID_NAME);
$archiver = isset($this->archivers['create'][$mime])
? $this->archivers['create'][$mime]
return $this->setError(elFinder::ERROR_ARCHIVE_TYPE);
$useRemoteArchive = !empty($this->options['useRemoteArchive']);
foreach ($hashes as $hash) {
if (($file = $this->file($hash)) == false) {
return $this->setError(elFinder::ERROR_FILE_NOT_FOUND, '#' . $hash);
return $this->setError(elFinder::ERROR_PERM_DENIED);
$path = $this->decode($hash);
$dir = $this->dirnameCE($path);
$stat = $this->stat($dir);
return $this->setError(elFinder::ERROR_PERM_DENIED);
$files[] = $useRemoteArchive ? $hash : $this->basenameCE($path);
$name = count($files) == 1 ? $files[0] : 'Archive';
$name = str_replace(array('/', '\\'), '_', preg_replace('/\.' . preg_quote($archiver['ext'], '/') . '$/i', '', $name));
$name .= '.' . $archiver['ext'];
$name = $this->uniqueName($dir, $name, '');
return ($path = $this->remoteArchive($files, $name, $archiver)) ? $this->stat($path) : false;
return ($path = $this->convEncOut($this->_archive($this->convEncIn($dir), $this->convEncIn($files), $this->convEncIn($name), $archiver))) ? $this->stat($path) : false;
* Create an archive from remote items
* @param array $hashes files hashes list
* @param string $name archive name
* @param array $arc archiver options
* @return string|boolean path of created archive
protected function remoteArchive($hashes, $name, $arc)
$file0 = $this->file($hashes[0]);
if ($file0 && ($dir = $this->getItemsInHand($hashes))) {
$files = self::localScandir($dir);
if ($arc = $this->makeArchive($dir, $files, $name, $arc)) {