: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
public function getUploadTaget($baseTargetHash, $path, & $result)
$base = $this->decode($baseTargetHash);
$targetHash = $baseTargetHash;
$path = ltrim($path, $this->separator);
$dirs = explode($this->separator, $path);
foreach ($dirs as $dir) {
$targetPath = $this->joinPathCE($base, $dir);
if (!$_realpath = $this->realpath($this->encode($targetPath))) {
if ($stat = $this->mkdir($targetHash, $dir)) {
$result['added'][] = $stat;
$targetHash = $stat['hash'];
$base = $this->decode($targetHash);
$targetHash = $this->encode($_realpath);
if ($this->dir($targetHash)) {
$base = $this->decode($targetHash);
* Return this uploadMaxSize value
public function getUploadMaxSize()
return $this->uploadMaxSize;
public function setUploadOverwrite($var)
$this->uploadOverwrite = (bool)$var;
* @param string $mode 'resize', 'rotate', 'propresize', 'crop', 'fitsquare'
* @param string $src Image file local path
* @param array $options excute options
* @throws ImagickException
* @throws elFinderAbortException
public function imageUtil($mode, $src, $options = array())
if (!isset($options['jpgQuality'])) {
$options['jpgQuality'] = intval($this->options['jpgQuality']);
if (!isset($options['bgcolor'])) {
$options['bgcolor'] = '#ffffff';
if (!isset($options['bgColorFb'])) {
$options['bgColorFb'] = $this->options['bgColorFb'];
$destformat = !empty($options['destformat'])? $options['destformat'] : null;
// check 'width' ,'height'
if (in_array($mode, array('resize', 'propresize', 'crop', 'fitsquare'))) {
if (empty($options['width']) || empty($options['height'])) {
if (!empty($options['checkAnimated'])) {
if ($this->imgLib !== 'imagick' && $this->imgLib !== 'convert') {
if (elFinder::isAnimationGif($src)) {
if (elFinder::isAnimationPng($src)) {
if (empty($options['degree'])) {
return (bool)$this->imgRotate($src, $options['degree'], $options['bgColorFb'], $destformat, $options['jpgQuality']);
return (bool)$this->imgResize($src, $options['width'], $options['height'], false, true, $destformat, $options['jpgQuality'], $options);
return (bool)$this->imgResize($src, $options['width'], $options['height'], true, true, $destformat, $options['jpgQuality'], $options);
if (isset($options['x']) && isset($options['y'])) {
return (bool)$this->imgCrop($src, $options['width'], $options['height'], $options['x'], $options['y'], $destformat, $options['jpgQuality']);
return (bool)$this->imgSquareFit($src, $options['width'], $options['height'], 'center', 'middle', $options['bgcolor'], $destformat, $options['jpgQuality']);
* Convert Video To Image by ffmpeg
* @param string $file video source file path
* @param array $stat file stat array
* @param object $self volume driver object
* @param int $ss start seconds
* @throws elFinderAbortException
public function ffmpegToImg($file, $stat, $self, $ss = null)
$tmp = $path . DIRECTORY_SEPARATOR . md5($name);
// register auto delete on shutdown
$GLOBALS['elFinderTempFiles'][$tmp] = true;
if (rename($file, $tmp)) {
// specific start time by file name (xxx^[sec].[extention] - video^3.mp4)
if (preg_match('/\^(\d+(?:\.\d+)?)\.[^.]+$/', $stat['name'], $_m)) {
$ss = $this->options['tmbVideoConvSec'];
$cmd = sprintf(ELFINDER_FFMPEG_PATH . ' -i %s -ss 00:00:%.3f -vframes 1 -f image2 -- %s', escapeshellarg($tmp), $ss, escapeshellarg($file));
$r = ($this->procExec($cmd) === 0);
if ($r && $ss > 0 && !file_exists($file)) {
$ss = max(intval($ss / 2), 0);
$r = $this->ffmpegToImg($file, $stat, $self, $ss);
* Creates a temporary file and return file pointer
* @return resource|boolean
public function tmpfile()
if ($tmp = $this->getTempFile()) {
return fopen($tmp, 'wb');
protected function setError()
$this->addError(func_get_args());
* @author Dmitry(dio) Levashov
protected function addError()
foreach (func_get_args() as $err) {
$this->error[] = (string)$err;
/*********************************************************************/
/*********************************************************************/
/***************** server encoding support *******************/
* Return parent directory path (with convert encoding)
* @param string $path file path
protected function dirnameCE($path)
$dirname = (!$this->encoding) ? $this->_dirname($path) : $this->convEncOut($this->_dirname($this->convEncIn($path)));
// check to infinite loop prevention
return ($dirname != $path) ? $dirname : '';
* Return file name (with convert encoding)
* @param string $path file path
protected function basenameCE($path)
return (!$this->encoding) ? $this->_basename($path) : $this->convEncOut($this->_basename($this->convEncIn($path)));
* Join dir name and file name and return full path. (with convert encoding)
* Some drivers (db) use int as path - so we give to concat path to driver itself
* @param string $dir dir path
* @param string $name file name
protected function joinPathCE($dir, $name)
return (!$this->encoding) ? $this->_joinPath($dir, $name) : $this->convEncOut($this->_joinPath($this->convEncIn($dir), $this->convEncIn($name)));
* Return normalized path (with convert encoding)
* @param string $path file path
protected function normpathCE($path)
return (!$this->encoding) ? $this->_normpath($path) : $this->convEncOut($this->_normpath($this->convEncIn($path)));
* Return file path related to root dir (with convert encoding)
* @param string $path file path
protected function relpathCE($path)
return (!$this->encoding) ? $this->_relpath($path) : $this->convEncOut($this->_relpath($this->convEncIn($path)));
* Convert path related to root dir into real path (with convert encoding)
* @param string $path rel file path
protected function abspathCE($path)
return (!$this->encoding) ? $this->_abspath($path) : $this->convEncOut($this->_abspath($this->convEncIn($path)));
* Return true if $path is children of $parent (with convert encoding)
* @param string $path path to check
* @param string $parent parent path
protected function inpathCE($path, $parent)
return (!$this->encoding) ? $this->_inpath($path, $parent) : $this->convEncOut($this->_inpath($this->convEncIn($path), $this->convEncIn($parent)));
* Open file and return file pointer (with convert encoding)
* @param string $path file path
* @internal param bool $write open file for writing
protected function fopenCE($path, $mode = 'rb')
// check extra option for network stream pointer
if (func_num_args() > 2) {
return (!$this->encoding) ? $this->_fopen($path, $mode, $opts) : $this->convEncOut($this->_fopen($this->convEncIn($path), $mode, $opts));
* Close opened file (with convert encoding)
* @param resource $fp file pointer
* @param string $path file path
protected function fcloseCE($fp, $path = '')
return (!$this->encoding) ? $this->_fclose($fp, $path) : $this->convEncOut($this->_fclose($fp, $this->convEncIn($path)));
* Create new file and write into it from file pointer. (with convert encoding)
* 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 saveCE($fp, $dir, $name, $stat)
$res = (!$this->encoding) ? $this->_save($fp, $dir, $name, $stat) : $this->convEncOut($this->_save($fp, $this->convEncIn($dir), $this->convEncIn($name), $this->convEncIn($stat)));
* Return true if path is dir and has at least one childs directory (with convert encoding)
* @param string $path dir path
protected function subdirsCE($path)
if ($this->sessionCaching['subdirs']) {
if (isset($this->sessionCache['subdirs'][$path]) && !$this->isMyReload()) {
return $this->sessionCache['subdirs'][$path];
$hasdir = (bool)((!$this->encoding) ? $this->_subdirs($path) : $this->convEncOut($this->_subdirs($this->convEncIn($path))));
$this->updateSubdirsCache($path, $hasdir);
* Return files list in directory (with convert encoding)
* @param string $path dir path
protected function scandirCE($path)
return (!$this->encoding) ? $this->_scandir($path) : $this->convEncOut($this->_scandir($this->convEncIn($path)));
* Create symlink (with convert encoding)
* @param string $source file to link to
* @param string $targetDir folder to create link in
* @param string $name symlink name
protected function symlinkCE($source, $targetDir, $name)
return (!$this->encoding) ? $this->_symlink($source, $targetDir, $name) : $this->convEncOut($this->_symlink($this->convEncIn($source), $this->convEncIn($targetDir), $this->convEncIn($name)));
/***************** paths *******************/
* @param string file path
* @author Dmitry (dio) Levashov
protected function encode($path)
// cut ROOT from $path for security reason, even if hacker decodes the path he will not know the root
$p = $this->relpathCE($path);
// if reqesting root dir $path will be empty, then assign '/' as we cannot leave it blank for crypt
if ($this->separatorForHash) {
$p = str_replace($this->separator, $this->separatorForHash, $p);
// TODO crypt path and return hash
$hash = $this->crypt($p);
// hash is used as id in HTML that means it must contain vaild chars
// make base64 html safe and append prefix in begining
$hash = strtr(base64_encode($hash), '+/=', '-_.');
// remove dots '.' at the end, before it was '=' in base64
$hash = rtrim($hash, '.');
// append volume id to make hash unique
return $this->id . $hash;
//TODO: Add return statement here
* @param string file hash
* @author Dmitry (dio) Levashov
protected function decode($hash)
if (strpos($hash, $this->id) === 0) {
// cut volume id after it was prepended in encode
$h = substr($hash, strlen($this->id));
// replace HTML safe base64 to normal
$h = base64_decode(strtr($h, '-_.', '+/='));
// TODO uncrypt hash and return path
$path = $this->uncrypt($h);
if ($this->separatorForHash) {
$path = str_replace($this->separatorForHash, $this->separator, $path);
// append ROOT to path after it was cut in encode
return $this->abspathCE($path);//$this->root.($path === $this->separator ? '' : $this->separator.$path);
* @author Dmitry (dio) Levashov
protected function crypt($path)