: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ($res = $this->_bd_fetch($url)) {
if ($res[0]->type == 'folder') {
* 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
* @author Dmitry (dio) Levashov
protected function _dimensions($path, $mime)
if (strpos($mime, 'image') !== 0) {
if ($work = $this->getWorkFile($path)) {
if ($size = @getimagesize($work)) {
$cache['width'] = $size[0];
$cache['height'] = $size[1];
$ret = array('dim' => $size[0] . 'x' . $size[1]);
$srcfp = fopen($work, 'rb');
$target = isset(elFinder::$currentArgs['target'])? elFinder::$currentArgs['target'] : '';
if ($subImgLink = $this->getSubstituteImgLink($target, $size, $srcfp)) {
$ret['url'] = $subImgLink;
is_file($work) && @unlink($work);
/******************** file/dir content *********************/
* Return files list in directory.
* @param string $path dir path
* @author Dmitry (dio) Levashov
* @author Cem (DiscoFever)
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
* @author Dmitry (dio) Levashov
protected function _fopen($path, $mode = 'rb')
if ($mode === 'rb' || $mode === 'r') {
list(, $itemId) = $this->_bd_splitPath($path);
'target' => self::API_URL . '/files/' . $itemId . '/content',
'headers' => array('Authorization: Bearer ' . $this->token->data->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
* @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)
list(, $parentId) = $this->_bd_splitPath($path);
$params = array('name' => $name, 'parent' => array('id' => $parentId));
$url = self::API_URL . '/folders';
$curl = $this->_bd_prepareCurl(array(
CURLOPT_POSTFIELDS => json_encode($params),
//create the Folder in the Parent
$folder = $this->_bd_curlExec($curl, $path);
return $this->_joinPath($path, $folder->id);
return $this->setError('Box 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
* @author Dmitry (dio) Levashov
protected function _mkfile($path, $name)
return $this->_save($this->tmpfile(), $path, $name, array());
* Create symlink. FTP driver does not support symlinks.
* @param string $target link target
* @param string $path symlink path
* @author Dmitry (dio) Levashov
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
* @author Dmitry (dio) Levashov
protected function _copy($source, $targetDir, $name)
list(, $parentId) = $this->_bd_splitPath($targetDir);
list(, $srcId) = $this->_bd_splitPath($source);
$srcItem = $this->_bd_getRawItem($source);
$properties = array('name' => $name, 'parent' => array('id' => $parentId));
$data = (object)$properties;
$type = ($srcItem->type === 'folder') ? 'folders' : 'files';
$url = self::API_URL . '/' . $type . '/' . $srcId . '/copy';
$curl = $this->_bd_prepareCurl(array(
CURLOPT_POSTFIELDS => json_encode($data),
//copy File in the Parent
$result = $this->_bd_curlExec($curl, $targetDir);
if (isset($result->id)) {
if ($type === 'folders' && isset($this->sessionCache['subdirs'])) {
$this->sessionCache['subdirs'][$targetDir] = true;
return $this->_joinPath($targetDir, $result->id);
return $this->setError('Box 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
* @author Dmitry (dio) Levashov
protected function _move($source, $targetDir, $name)
//moving and renaming a file or directory
//Set new Parent and remove old parent
list(, $parentId) = $this->_bd_splitPath($targetDir);
list(, $itemId) = $this->_bd_splitPath($source);
$srcItem = $this->_bd_getRawItem($source);
//rename or move file or folder in destination target
$properties = array('name' => $name, 'parent' => array('id' => $parentId));
$type = ($srcItem->type === 'folder') ? 'folders' : 'files';
$url = self::API_URL . '/' . $type . '/' . $itemId;
$data = (object)$properties;
$curl = $this->_bd_prepareCurl(array(
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => json_encode($data),
$result = $this->_bd_curlExec($curl, $targetDir, array(
// The data is sent as JSON as per Box documentation.
'Content-Type: application/json',
if ($result && isset($result->id)) {
return $this->_joinPath($targetDir, $result->id);
return $this->setError('Box error: ' . $e->getMessage());
* @param string $path file path
* @author Dmitry (dio) Levashov
protected function _unlink($path)
return $this->_bd_unlink($path, 'files');
* @param string $path dir path
* @author Dmitry (dio) Levashov
protected function _rmdir($path)
return $this->_bd_unlink($path, 'folders');
* 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, $path, $name, $stat)
list($parentId, $itemId, $parent) = $this->_bd_splitPath($path);
if (isset($stat['name'])) {
if (isset($stat['rev']) && strpos($stat['hash'], $this->id) === 0) {
list(, $parentId) = $this->_bd_splitPath($path);
//Create or Update a file
$metaDatas = stream_get_meta_data($fp);
$tmpFilePath = isset($metaDatas['uri']) ? $metaDatas['uri'] : '';
if (!$tmpFilePath || empty($metaDatas['seekable'])) {
$tmpHandle = $this->tmpfile();
stream_copy_to_stream($fp, $tmpHandle);
$metaDatas = stream_get_meta_data($tmpHandle);
$tmpFilePath = $metaDatas['uri'];
//upload or create new file in destination target
$properties = array('name' => $name, 'parent' => array('id' => $parentId));
$url = self::UPLOAD_URL . '/files/content';
//update existing file in destination target
$properties = array('name' => $name);
$url = self::UPLOAD_URL . '/files/' . $itemId . '/content';
if (class_exists('CURLFile')) {
$cfile = new CURLFile($tmpFilePath);
$cfile = '@' . $tmpFilePath;
$params = array('attributes' => json_encode($properties), 'file' => $cfile);
$curl = $this->_bd_prepareCurl(array(
CURLOPT_POSTFIELDS => $params,
$file = $this->_bd_curlExec($curl, $parent);
return $this->_joinPath($parent, $file->entries[0]->id);
return $this->setError('Box error: ' . $e->getMessage());
* @param string $path file path
* @author Dmitry (dio) Levashov
protected function _getContents($path)
list(, $itemId) = $this->_bd_splitPath($path);
$url = self::API_URL . '/files/' . $itemId . '/content';
$contents = $this->_bd_fetch($url, true);
return $this->setError('Box error: ' . $e->getMessage());
* 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)
if ($local = $this->getTempFile($path)) {
if (file_put_contents($local, $content, LOCK_EX) !== false
&& ($fp = fopen($local, 'rb'))) {
$res = $this->_save($fp, $path, '', array());
file_exists($local) && unlink($local);
* Detect available archivers.
protected function _checkArchivers()
// die('Not yet implemented. (_checkArchivers)');
protected function _chmod($path, $mode)
* 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)');
* 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
* @author Dmitry (dio) Levashov,
* @author Alexey Sukhotin
protected function _archive($dir, $files, $name, $arc)
die('Not yet implemented. (_archive)');