: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @author Dmitry (dio) Levashov
protected function _relpath($path)
if ($path === $this->root) {
return ltrim(substr($path, strlen($this->root)), '/');
* Convert path related to root dir into real path.
* @param string $path file path
protected function _abspath($path)
return $this->_joinPath($this->root, $path);
* Return fake path started from root dir.
* @param string $path file path
protected function _path($path)
$path = $this->_normpath(substr($path, strlen($this->root)));
* Return true if $path is children of $parent.
* @param string $path path to check
* @param string $parent parent path
protected function _inpath($path, $parent)
return $path == $parent || strpos($path, $parent . '/') === 0;
/***************** file stat ********************/
* Return stat for given path.
* Stat contains following fields:
* - (int) size file size in b. required
* - (int) ts file modification time in unix time. required
* - (string) mime mimetype. required for folders, others - optionally
* - (bool) read read permissions. required
* - (bool) write write permissions. required
* - (bool) locked is object locked. optionally
* - (bool) hidden is object hidden. optionally
* - (string) alias for symlinks - link target path relative to root path. optionally
* - (string) target for symlinks - link target path. optionally.
* If file does not exists - returns empty array or false.
* @param string $path file path
* @author Dmitry (dio) Levashov
protected function _stat($path)
if ($raw = $this->_db_getFile($path)) {
return $this->_db_parseRaw($raw);
* Return true if path is dir and has at least one childs directory.
* @param string $path dir path
protected function _subdirs($path)
$res = $this->service->listFolder($path);
$items = $res->getItems();
foreach ($items as $raw) {
if ($raw instanceof FolderMetadata) {
} catch (DropboxClientException $e) {
$this->setError('Dropbox error: ' . $e->getMessage());
* Return object width and height
* Ususaly used for images, but can be realize for video etc...
* @param string $path file path
* @param string $mime file mime type
* @throws ImagickException
* @throws elFinderAbortException
protected function _dimensions($path, $mime)
if (strpos($mime, 'image') !== 0) {
if ($data = $this->_getContents($path)) {
$tmp = $this->getTempFile();
file_put_contents($tmp, $data);
$size = getimagesize($tmp);
$ret = array('dim' => $size[0] . 'x' . $size[1]);
$srcfp = fopen($tmp, 'rb');
$target = isset(elFinder::$currentArgs['target'])? elFinder::$currentArgs['target'] : '';
if ($subImgLink = $this->getSubstituteImgLink($target, $size, $srcfp)) {
$ret['url'] = $subImgLink;
/******************** file/dir content *********************/
* Return files list in directory.
* @param string $path dir path
protected function _scandir($path)
return isset($this->dirsCache[$path])
? $this->dirsCache[$path]
: $this->cacheDir($path);
* Open file and return file pointer.
* @param string $path file path
* @param bool $write open file for writing
protected function _fopen($path, $mode = 'rb')
if ($mode === 'rb' || $mode === 'r') {
if ($link = $this->service->getTemporaryLink($path)) {
$access_token = $this->service->getAccessToken();
'target' => $link->getLink(),
'headers' => array('Authorization: Bearer ' . $access_token),
// to support range request
if (func_num_args() > 2) {
if (!empty($opts['httpheaders'])) {
$data['headers'] = array_merge($opts['httpheaders'], $data['headers']);
return elFinder::getStreamByUrl($data);
* @param resource $fp file pointer
protected function _fclose($fp, $path = '')
is_resource($fp) && fclose($fp);
/******************** file/dir manipulations *************************/
* Create dir and return created dir path or false on failed.
* @param string $path parent dir path
* @param string $name new directory name
protected function _mkdir($path, $name)
return $this->service->createFolder($this->_db_joinName($path, $name))->getPathLower();
} catch (DropboxClientException $e) {
return $this->setError('Dropbox error: ' . $e->getMessage());
* Create file and return it's path or false on failed.
* @param string $path parent dir path
* @param string $name new file name
protected function _mkfile($path, $name)
return $this->_save($this->tmpfile(), $path, $name, []);
* Create symlink. FTP driver does not support symlinks.
* @param string $target link target
* @param string $path symlink path
protected function _symlink($target, $path, $name)
* Copy file into another file.
* @param string $source source file path
* @param string $targetDir target directory path
* @param string $name new file name
protected function _copy($source, $targetDir, $name)
$this->service->copy($source, $this->_db_joinName($targetDir, $name))->getPathLower();
} catch (DropboxClientException $e) {
return $this->setError('Dropbox error: ' . $e->getMessage());
* Move file into another parent dir.
* Return new file path or false.
* @param string $source source file path
* @param string $target target dir path
* @param string $name file name
protected function _move($source, $targetDir, $name)
return $this->service->move($source, $this->_db_joinName($targetDir, $name))->getPathLower();
} catch (DropboxClientException $e) {
return $this->setError('Dropbox error: ' . $e->getMessage());
* @param string $path file path
protected function _unlink($path)
$this->service->delete($path);
} catch (DropboxClientException $e) {
return $this->setError('Dropbox error: ' . $e->getMessage());
* @param string $path dir path
protected function _rmdir($path)
return $this->_unlink($path);
* Create new file and write into it from file pointer.
* Return new file path or false on error.
* @param resource $fp file pointer
* @param string $dir target dir path
* @param string $name file name
* @param array $stat file stat (required by some virtual fs)
protected function _save($fp, $path, $name, $stat)
$info = stream_get_meta_data($fp);
if (empty($info['uri']) || preg_match('#^[a-z0-9.-]+://#', $info['uri'])) {
if ($filepath = $this->getTempFile()) {
$_fp = fopen($filepath, 'wb');
stream_copy_to_stream($fp, $_fp);
$filepath = $info['uri'];
$dropboxFile = new DropboxFile($filepath);
$fullpath = $this->_db_joinName($path, $name);
return $this->service->upload($dropboxFile, $fullpath, ['mode' => 'overwrite'])->getPathLower();
} catch (DropboxClientException $e) {
return $this->setError('Dropbox error: ' . $e->getMessage());
* @param string $path file path
protected function _getContents($path)
$file = $this->service->download($path);
$contents = $file->getContents();
return $this->setError('Dropbox error: ' . $e->getMessage());
* Write a string to a file.
* @param string $path file path
* @param string $content new file content
protected function _filePutContents($path, $content)
if ($local = $this->getTempFile($path)) {
if (file_put_contents($local, $content, LOCK_EX) !== false
&& ($fp = fopen($local, 'rb'))) {
$stat = $this->stat($path);
$path = $this->_dirname($path);
$res = $this->_save($fp, $path, $name, []);
file_exists($local) && unlink($local);
* Detect available archivers.
protected function _checkArchivers()
// die('Not yet implemented. (_checkArchivers)');
protected function _chmod($path, $mode)
* @param string $path archive path
* @param array $arc archiver command and arguments (same as in $this->archivers)
* @author Dmitry (dio) Levashov
* @author Alexey Sukhotin
protected function _unpack($path, $arc)
die('Not yet implemented. (_unpack)');
* Recursive symlinks search.
* @param string $path file/dir path
* @author Dmitry (dio) Levashov
protected function _findSymlinks($path)
die('Not yet implemented. (_findSymlinks)');
* Extract files from archive.
* @param string $path archive path
* @param array $arc archiver command and arguments (same as in $this->archivers)
* @author Dmitry (dio) Levashov,
* @author Alexey Sukhotin
protected function _extract($path, $arc)
die('Not yet implemented. (_extract)');