: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if (!is_array($hashes)) {
$hashes = array($hashes);
foreach ($hashes as $hash) {
$lock = elFinder::$commonTempPath . DIRECTORY_SEPARATOR . self::filenameDecontaminate($hash) . '.lock';
if ($this->itemLocked($hash)) {
$cnt = file_get_contents($lock) + 1;
if (file_put_contents($lock, $cnt, LOCK_EX)) {
$this->autoUnlocks[] = $hash;
protected function itemUnlock($hash)
if (!$this->itemLocked($hash)) {
$lock = elFinder::$commonTempPath . DIRECTORY_SEPARATOR . $hash . '.lock';
$cnt = file_get_contents($lock);
file_put_contents($lock, $cnt, LOCK_EX);
* unlock locked items on command completion
public function itemAutoUnlock()
if ($this->autoUnlocks) {
foreach ($this->autoUnlocks as $hash) {
$this->itemUnlock($hash);
$this->autoUnlocks = array();
* Ensure directories recursively
* @param object $volume Volume object
* @param string $target Target hash
* @param array $dirs Array of directory tree to ensure
* @param string $path Relative path form target hash
* @return array|false array('stats' => array([stat of maked directory]), 'hashes' => array('[path]' => '[hash]'), 'makes' => array([New directory hashes]), 'error' => array([Error name]))
protected function ensureDirsRecursively($volume, $target, $dirs, $path = '')
$res = array('stats' => array(), 'hashes' => array(), 'makes' => array(), 'error' => array());
foreach ($dirs as $name => $sub) {
if ((($parent = $volume->realpath($target)) && ($dir = $volume->dir($volume->getHash($parent, $name)))) || ($newDir = $volume->mkdir($target, $name))) {
$_path = $path . '/' . $name;
$res['makes'][] = $newDir['hash'];
$res['hashes'][$_path] = $dir['hash'];
$res = array_merge_recursive($res, $this->ensureDirsRecursively($volume, $dir['hash'], $sub, $_path));
* Sets the toast error handler.
* @param array $opts The options
public function setToastErrorHandler($opts)
$this->toastParams = $this->toastParamsDefault;
$this->toastParams = array_merge($this->toastParams, $opts);
set_error_handler(array($this, 'toastErrorHandler'));
* String encode convert to UTF-8
* @param string $str Input string
* @return string UTF-8 string
public function utf8Encode($str)
if (@iconv('utf-8', 'utf-8//IGNORE', $str) === $str) {
if ($this->utf8Encoder) {
return $this->utf8Encoder($str);
if ($mbencode === null) {
$mbencode = function_exists('mb_convert_encoding') && function_exists('mb_detect_encoding');
if ($enc = mb_detect_encoding($str, mb_detect_order(), true)) {
$_str = mb_convert_encoding($str, 'UTF-8', $enc);
if (@iconv('utf-8', 'utf-8//IGNORE', $_str) === $_str) {
return utf8_encode($str);
/***************************************************************************/
/***************************************************************************/
* Return full version of API that this connector supports all functions
public static function getApiFullVersion()
return (string)self::$ApiVersion . '.' . (string)self::$ApiRevision;
* Return self::$commonTempPath
* @return string The common temporary path.
public static function getCommonTempPath()
return self::$commonTempPath;
* Return Is Animation Gif
* @param string $path server local path of target image
public static function isAnimationGif($path)
list(, , $type) = getimagesize($path);
$fp = fopen($path, 'rb');
if (ord($c) != 0x39) { // GIF89a
} while (ord($c) != 0x21 && !feof($fp));
if (bin2hex($c2) == "f904") {
* Return Is Animation Png
* @param string $path server local path of target image
public static function isAnimationPng($path)
list(, , $type) = getimagesize($path);
$fp = fopen($path, 'rb');
$img_bytes = fread($fp, 1024);
if (strpos(substr($img_bytes, 0, strpos($img_bytes, 'IDAT')), 'acTL') !== false) {
* Return Is seekable stream resource
* @param resource $resource
public static function isSeekableStream($resource)
$metadata = stream_get_meta_data($resource);
return $metadata['seekable'];
* @param resource $resource
public static function rewind($resource)
self::isSeekableStream($resource) && rewind($resource);
* Determines whether the specified resource is seekable url.
* @param <type> $resource The resource
* @return boolean True if the specified resource is seekable url, False otherwise.
public static function isSeekableUrl($resource)
if (isset(elFinder::$seekableUrlFps[$id])) {
return elFinder::$seekableUrlFps[$id];
* serialize and base64_encode of session data (If needed)
* @param mixed $var target variable
public static function sessionDataEncode($var)
if (self::$base64encodeSessionData) {
$var = base64_encode(serialize($var));
* base64_decode and unserialize of session data (If needed)
* @param mixed $var target variable
* @param bool $checkIs data type for check (array|string|object|int)
public static function sessionDataDecode(&$var, $checkIs = null)
if (self::$base64encodeSessionData) {
$data = unserialize(base64_decode($var));
* Call session_write_close() if session is restarted
public static function sessionWrite()
* Return elFinder static variable
public static function getStaticVar($key)
return isset(elFinder::$$key) ? elFinder::$$key : null;
* Extend PHP execution time limit and also check connection is aborted
* @throws elFinderAbortException
public static function extendTimeLimit($time = null)
if (is_null($defLimit)) {
$defLimit = ini_get('max_execution_time');
$time = is_null($time) ? $defLimit : max($defLimit, $time);
throw new elFinderAbortException();
* Check connection is aborted
* Script stop immediately if connection aborted
* @throws elFinderAbortException
public static function checkAborted()
elFinder::extendTimeLimit();
* Return bytes from php.ini value
public static function getIniBytes($iniName = '', $val = '')
$val = ini_get($iniName);
$val = trim($val, "bB \t\n\r\0\x0B");
$last = strtolower($val[strlen($val) - 1]);
$val = sprintf('%u', $val);
$val = elFinder::xKilobyte($val);
$val = elFinder::xKilobyte($val);
$val = elFinder::xKilobyte($val);
$val = elFinder::xKilobyte($val);
$val = elFinder::xKilobyte($val);
$val = elFinder::xKilobyte($val);
$val = elFinder::xKilobyte($val);
$val = elFinder::xKilobyte($val);
* @param integer|string $val The value
public static function xKilobyte($val)
if (strpos((string)$val * 1024, 'E') !== false) {
if (strpos((string)$val * 1.024, 'E') === false) {
* @return string full URL
public static function getConnectorUrl()
if (defined('ELFINDER_CONNECTOR_URL')) {
return ELFINDER_CONNECTOR_URL;
$https = (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off');
$url = ($https ? 'https://' : 'http://')
. $_SERVER['SERVER_NAME'] // host
. ((empty($_SERVER['SERVER_PORT']) || (!$https && $_SERVER['SERVER_PORT'] == 80) || ($https && $_SERVER['SERVER_PORT'] == 443)) ? '' : (':' . $_SERVER['SERVER_PORT'])) // port
. $_SERVER['REQUEST_URI']; // path & query
list($url) = explode('?', $url);
* Get stream resource pointer by URL
* @param array $data array('target'=>'URL', 'headers' => array())
* @param int $redirectLimit
* @return resource|boolean