: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ($fp = fopen($arc, 'rb')) {
'size' => $fstat['size'],
'mime' => $this->mimetype($arc, $name)
$path = $this->decode($file0['phash']);
$resPath = $this->saveCE($fp, $path, $name, $stat);
$this->rmdirRecursive($dir);
* @param string $hash image file
* @param int $width new width
* @param int $height new height
* @param int $x X start poistion for crop
* @param int $y Y start poistion for crop
* @param string $mode action how to mainpulate image
* @param string $bg background color
* @param int $degree rotete degree
* @param int $jpgQuality JEPG quality (1-100)
* @throws ImagickException
* @throws elFinderAbortException
* @author Dmitry (dio) Levashov
* @author Alexey Sukhotin
public function resize($hash, $width, $height, $x, $y, $mode = 'resize', $bg = '', $degree = 0, $jpgQuality = null)
if ($this->commandDisabled('resize')) {
return $this->setError(elFinder::ERROR_PERM_DENIED);
if ($mode === 'rotate' && $degree == 0) {
return array('losslessRotate' => ($this->procExec(ELFINDER_EXIFTRAN_PATH . ' -h') === 0 || $this->procExec(ELFINDER_JPEGTRAN_PATH . ' -version') === 0));
if (($file = $this->file($hash)) == false) {
return $this->setError(elFinder::ERROR_FILE_NOT_FOUND);
if (!$file['write'] || !$file['read']) {
return $this->setError(elFinder::ERROR_PERM_DENIED);
$path = $this->decode($hash);
$work_path = $this->getWorkFile($this->encoding ? $this->convEncIn($path, true) : $path);
if (!$work_path || !is_writable($work_path)) {
if ($work_path && $path !== $work_path && is_file($work_path)) {
return $this->setError(elFinder::ERROR_PERM_DENIED);
if ($this->imgLib !== 'imagick' && $this->imgLib !== 'convert') {
if (elFinder::isAnimationGif($work_path)) {
return $this->setError(elFinder::ERROR_UNSUPPORT_TYPE);
if (elFinder::isAnimationPng($work_path)) {
return $this->setError(elFinder::ERROR_UNSUPPORT_TYPE);
$result = $this->imgResize($work_path, $width, $height, true, true, null, $jpgQuality);
$result = $this->imgCrop($work_path, $width, $height, $x, $y, null, $jpgQuality);
$result = $this->imgSquareFit($work_path, $width, $height, 'center', 'middle', ($bg ? $bg : $this->options['tmbBgColor']), null, $jpgQuality);
$result = $this->imgRotate($work_path, $degree, ($bg ? $bg : $this->options['bgColorFb']), null, $jpgQuality);
$result = $this->imgResize($work_path, $width, $height, false, true, null, $jpgQuality);
$fstat = stat($work_path);
$imgsize = getimagesize($work_path);
if ($path !== $work_path) {
$file['size'] = $fstat['size'];
$file['ts'] = $fstat['mtime'];
$file['width'] = $imgsize[0];
$file['height'] = $imgsize[1];
if ($fp = fopen($work_path, 'rb')) {
$ret = $this->saveCE($fp, $this->dirnameCE($path), $this->basenameCE($path), $file);
$ret = $this->stat($path);
$ret['width'] = $imgsize[0];
$ret['height'] = $imgsize[1];
if ($path !== $work_path) {
is_file($work_path) && unlink($work_path);
* @param string $hash file hash
* @throws elFinderAbortException
* @author Dmitry (dio) Levashov
public function rm($hash)
return $this->commandDisabled('rm')
? $this->setError(elFinder::ERROR_PERM_DENIED)
: $this->remove($this->decode($hash));
* @param string $q search string
* @throws elFinderAbortException
* @author Dmitry (dio) Levashov
public function search($q, $mimes, $hash = null)
$matchMethod = 'searchMatch' . $args[3];
if (!is_callable(array($this, $matchMethod))) {
$dir = $this->decode($hash);
$stat = $this->stat($dir);
if (!$stat || $stat['mime'] !== 'directory' || !$stat['read']) {
if ($mimes && $this->onlyMimes) {
$mimes = array_intersect($mimes, $this->onlyMimes);
$this->searchStart = time();
$qs = preg_split('/"([^"]+)"| +/', $q, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
$query = $excludes = array();
$excludes[] = substr($_q, 1);
$this->doSearchCurrentQuery = array(
'matchMethod' => $matchMethod
if ($q === '' || $this->commandDisabled('search')) {
// valided regex $this->options['searchExDirReg']
if ($this->options['searchExDirReg']) {
if (false === preg_match($this->options['searchExDirReg'], '')) {
$this->options['searchExDirReg'] = '';
// check the leaf root too
if (!$mimes && (is_null($dir) || $dir == $this->root)) {
$rootStat = $this->stat($this->root);
if (!empty($rootStat['phash'])) {
if ($this->stripos($rootStat['name'], $q) !== false) {
return array_merge($res, $this->doSearch(is_null($dir) ? $this->root : $dir, $q, $mimes));
* Return image dimensions
* @param string $hash file hash
* @author Dmitry (dio) Levashov
public function dimensions($hash)
if (($file = $this->file($hash)) == false) {
// Throw additional parameters for some drivers
if (func_num_args() > 1) {
return $this->convEncOut($this->_dimensions($this->convEncIn($this->decode($hash)), $file['mime'], $args));
* @param string $hash file hash
public function subdirs($hash)
return (bool)$this->subdirsCE($this->decode($hash));
* Return content URL (for netmout volume driver)
* If file.url == 1 requests from JavaScript client with XHR
* @param string $hash file hash
* @param array $options options array
public function getContentUrl($hash, $options = array())
if (($file = $this->file($hash)) === false) {
if (!empty($options['onetime']) && $this->options['onetimeUrl']) {
if (is_callable($this->options['onetimeUrl'])) {
return call_user_func_array($this->options['onetimeUrl'], array($file, $options, $this));
if ($tmpdir = elFinder::getStaticVar('commonTempPath')) {
if ($source = $this->open($hash)) {
if ($_dat = tempnam($tmpdir, 'ELF')) {
$token = md5($_dat . session_id());
$dat = $tmpdir . DIRECTORY_SEPARATOR . 'ELF' . $token;
if (rename($_dat, $dat)) {
$info = stream_get_meta_data($source);
if (!empty($info['uri'])) {
$tmp = tempnam($tmpdir, 'ELF');
if ($dest = fopen($tmp, 'wb')) {
if (!stream_copy_to_stream($source, $dest)) {
$this->close($source, $hash);
'file' => base64_encode($tmp),
if (file_put_contents($dat, json_encode($info))) {
$conUrl = elFinder::getConnectorUrl();
$ret = $conUrl . (strpos($conUrl, '?') !== false? '&' : '?') . 'cmd=file&onetime=1&target=' . $token;
if (empty($file['url']) && $this->URL) {
$path = str_replace($this->separator, '/', substr($this->decode($hash), strlen(rtrim($this->root, '/' . $this->separator)) + 1));
$path = $this->convEncIn($path, true);
$path = str_replace('%2F', '/', rawurlencode($path));
return $this->URL . $path;
if (!empty($file['url']) && $file['url'] != 1) {
} else if (!empty($options['temporary']) && ($tempInfo = $this->getTempLinkInfo('temp_' . md5($hash . session_id())))) {
if (is_readable($tempInfo['path'])) {
touch($tempInfo['path']);
$ret = $tempInfo['url'] . '?' . rawurlencode($file['name']);
} else if ($source = $this->open($hash)) {
if ($dest = fopen($tempInfo['path'], 'wb')) {
if (stream_copy_to_stream($source, $dest)) {
$ret = $tempInfo['url'] . '?' . rawurlencode($file['name']);
$this->close($source, $hash);
* Get temporary contents link infomation
public function getTempLinkInfo($name = null)
if ($this->tmpLinkPath) {
$name = 'temp_' . md5($_SERVER['REMOTE_ADDR'] . (string)microtime(true));
} else if (substr($name, 0, 5) !== 'temp_') {
register_shutdown_function(array('elFinder', 'GlobGC'), $this->tmpLinkPath . DIRECTORY_SEPARATOR . 'temp_*', elFinder::$tmpLinkLifeTime);
'path' => $path = $this->tmpLinkPath . DIRECTORY_SEPARATOR . $name,
'url' => $this->tmpLinkUrl . '/' . rawurlencode($name)
* Get URL of substitute image by request args `substitute` or 4th argument $maxSize
* @param string $target Target hash
* @param array $srcSize Size info array [width, height]
* @param resource $srcfp Source file file pointer
* @param integer $maxSize Maximum pixel of substitute image
* @throws ImagickException
* @throws elFinderAbortException
public function getSubstituteImgLink($target, $srcSize, $srcfp = null, $maxSize = null)
$file = $this->file($target);
$force = !in_array($file['mime'], array('image/jpeg', 'image/png', 'image/gif'));
$args = elFinder::$currentArgs;
if (!empty($args['substitute'])) {
$maxSize = $args['substitute'];
if ($maxSize && $srcSize[0] && $srcSize[1]) {
if ($this->getOption('substituteImg')) {
$maxSize = intval($maxSize);
$zoom = min(($maxSize / $srcSize[0]), ($maxSize / $srcSize[1]));
if ($force || $zoom < 1) {
$width = round($srcSize[0] * $zoom);
$height = round($srcSize[1] * $zoom);
$destformat = $file['mime'] === 'image/jpeg'? null : 'png';
elFinder::checkAborted();
$srcfp = $this->open($target);
if ($srcfp && ($tempLink = $this->getTempLinkInfo())) {
elFinder::checkAborted();
$dest = fopen($tempLink['path'], 'wb');
if ($dest && stream_copy_to_stream($srcfp, $dest)) {
if ($this->imageUtil('resize', $tempLink['path'], compact('width', 'height', 'jpgQuality', 'preserveExif', 'unenlarge', 'checkAnimated', 'destformat'))) {
// set expire to 1 min left
touch($tempLink['path'], time() - elFinder::$tmpLinkLifeTime + 60);
unlink($tempLink['path']);
$this->close($srcfp, $target);
public function getTempPath()
if (isset($this->tmpPath) && $this->tmpPath && is_writable($this->tmpPath)) {
$tempPath = $this->tmpPath;
} else if (isset($this->tmp) && $this->tmp && is_writable($this->tmp)) {
} else if (elFinder::getStaticVar('commonTempPath') && is_writable(elFinder::getStaticVar('commonTempPath'))) {
$tempPath = elFinder::getStaticVar('commonTempPath');
} else if (function_exists('sys_get_temp_dir')) {
$tempPath = sys_get_temp_dir();
} else if ($this->tmbPathWritable) {
$tempPath = $this->tmbPath;
if ($tempPath && DIRECTORY_SEPARATOR !== '/') {
$tempPath = str_replace('/', DIRECTORY_SEPARATOR, $tempPath);
} else if (defined( 'WP_TEMP_DIR' )) {
$custom_temp_path = WP_CONTENT_DIR.'/temp';
if (!is_dir($custom_temp_path)) {
mkdir($custom_temp_path, 0777, true);
return $custom_temp_path;
* (Make &) Get upload taget dirctory hash
* @param string $baseTargetHash