: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$stat = $this->convEncIn(isset($this->cache[$outPath]) ? $this->cache[$outPath] : array());
// dispose incomplete cache made by calling `stat` by 'startPath' option
* Return true if path is dir and has at least one childs directory
* @param string $path dir path
* @author Dmitry (dio) Levashov, sitecode
protected function _subdirs($path)
foreach ($this->ftpRawList($path) as $info) {
$name = $info['filename'];
if ($name && $name !== '.' && $name !== '..' && $info['type'] == NET_SFTP_TYPE_DIRECTORY) {
if ($name && $name !== '.' && $name !== '..' && $info['type'] == NET_SFTP_TYPE_SYMLINK) {
/******************** file/dir content *********************/
* Open file and return file pointer
* @param string $path file path
* @throws elFinderAbortException
* @internal param bool $write open file for writing
* @author Dmitry (dio) Levashov
protected function _fopen($path, $mode = 'rb')
$local = $this->getTempFile($path);
$this->connect->get($path, $local);
return @fopen($local, $mode);
* @param resource $fp file pointer
* @author Dmitry (dio) Levashov
protected function _fclose($fp, $path = '')
is_resource($fp) && fclose($fp);
unlink($this->getTempFile($path));
/******************** 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
* @author Dmitry (dio) Levashov
protected function _mkdir($path, $name)
$path = $this->_joinPath($path, $this->_basename($name));
if ($this->connect->mkdir($path) === false) {
$this->options['dirMode'] && $this->connect->chmod($this->options['dirMode'], $path);
* 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)
$path = $this->_joinPath($path, $this->_basename($name));
return $this->connect->put($path, '') ? $path : false;
$path = $this->_joinPath($path, $name);
$local = $this->getTempFile();
$res = touch($local) && $this->connect->put($path, $local, NET_SFTP_LOCAL_FILE);
return $res ? $path : false;
* Copy file into another file
* @param string $source source file path
* @param string $targetDir target directory path
* @param string $name new file name
* @author Dmitry (dio) Levashov, sitecode
protected function _copy($source, $targetDir, $name)
$target = $this->_joinPath($targetDir, $this->_basename($name));
$local = $this->getTempFile();
if ($this->connect->get($source, $local)
&& $this->connect->put($target, $local, NET_SFTP_LOCAL_FILE)) {
$res = $this->_filePutContents($target, $this->_getContents($source));
* Move file into another parent dir.
* Return new file path or false.
* @param string $source source file path
* @param string $name file name
* @internal param string $target target dir path
* @author Dmitry (dio) Levashov
protected function _move($source, $targetDir, $name)
$target = $this->_joinPath($targetDir, $this->_basename($name));
return $this->connect->rename($source, $target) ? $target : false;
* @param string $path file path
* @author Dmitry (dio) Levashov
protected function _unlink($path)
return $this->connect->delete($path, false);
* @param string $path dir path
* @author Dmitry (dio) Levashov
protected function _rmdir($path)
return $this->connect->delete($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)
* @author Dmitry (dio) Levashov
protected function _save($fp, $dir, $name, $stat)
//TODO optionally encrypt $fp before uploading if mime is not already encrypted type
$path = $this->_joinPath($dir, $this->_basename($name));
return $this->connect->put($path, $fp)
* @param string $path file path
* @throws elFinderAbortException
* @author Dmitry (dio) Levashov
protected function _getContents($path)
return $this->connect->get($path);
* Write a string to a file
* @param string $path file path
* @param string $content new file content
* @author Dmitry (dio) Levashov
protected function _filePutContents($path, $content)
return $this->connect->put($path, $content);
protected function _chmod($path, $mode)
$modeOct = is_string($mode) ? octdec($mode) : octdec(sprintf("%04o", $mode));
return $this->connect->chmod($modeOct, $path);
* Extract files from archive
* @param string $path archive path
* @param array $arc archiver command and arguments (same as in $this->archivers)
* @throws elFinderAbortException
* @author Dmitry (dio) Levashov,
* @author Alexey Sukhotin
protected function _extract($path, $arc)
* Create archive and return its path
* @param string $dir target dir
* @param array $files files names list
* @param string $name archive name
* @param array $arc archiver options
* @throws elFinderAbortException
* @author Dmitry (dio) Levashov,
* @author Alexey Sukhotin
protected function _archive($dir, $files, $name, $arc)
* Gets an array of absolute remote SFTP paths of files and
* folders in $remote_directory omitting symbolic links.
* @param $remote_directory string remote SFTP path to scan for file and folders recursively
* @param $targets array Array of target item. `null` is to get all of items
* @return array of elements each of which is an array of two elements:
* <li>$item['path'] - absolute remote SFTP path</li>
* <li>$item['type'] - either 'f' for file or 'd' for directory</li>
protected function ftp_scan_dir($remote_directory, $targets = null)
$buff = $this->ftpRawList($remote_directory);
if ($targets && is_array($targets)) {
$targets = array_flip($targets);
foreach ($buff as $info) {
$name = $info['filename'];
if ($name !== '.' && $name !== '..' && (!$targets || isset($targets[$name]))) {
case NET_SFTP_TYPE_SYMLINK : //omit symbolic links
case NET_SFTP_TYPE_DIRECTORY :
$remote_file_path = $this->_joinPath($remote_directory, $name);
$item['path'] = $remote_file_path;
$item['type'] = 'd'; // normal file
$items = array_merge($items, $this->ftp_scan_dir($remote_file_path));
$remote_file_path = $this->_joinPath($remote_directory, $name);
$item['path'] = $remote_file_path;
$item['type'] = 'f'; // normal file