: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* - (bool) read read permissions. required
* - (bool) write write permissions. required
* - (bool) locked is object locked. optionally
* - (bool) hidden is object hidden. optionally
* - (string) alias for symlinks - link target path relative to root path. optionally
* - (string) target for symlinks - link target path. optionally.
* If file does not exists - returns empty array or false.
* @param string $path file path
* @author Dmitry (dio) Levashov
protected function _stat($path)
if ($raw = $this->_od_getFileRaw($path)) {
$stat = $this->_od_parseRaw($raw);
if ($path === $this->root) {
$stat['expires'] = $this->expires;
* Return true if path is dir and has at least one childs directory.
* @param string $path dir path
* @throws elFinderAbortException
* @author Dmitry (dio) Levashov
protected function _subdirs($path)
list(, $itemId) = $this->_od_splitPath($path);
return (bool)$this->_od_query($itemId, false, false, array(
'filter' => 'folder ne null',
* 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 elFinderAbortException
* @author Dmitry (dio) Levashov
protected function _dimensions($path, $mime)
if (strpos($mime, 'image') !== 0) {
//$cache = $this->_od_getFileRaw($path);
if (func_num_args() > 2) {
if (!empty($args['substitute'])) {
$tmbSize = intval($args['substitute']);
list(, $itemId) = $this->_od_splitPath($path);
$tmb = 'c' . $tmbSize . 'x' . $tmbSize;
$options['query']['expand'] = 'thumbnails(select=' . $tmb . ')';
$raw = $this->_od_query($itemId, true, false, $options);
if ($raw && property_exists($raw, 'image') && $img = $raw->image) {
if (isset($img->width) && isset($img->height)) {
$ret = array('dim' => $img->width . 'x' . $img->height);
$srcSize = explode('x', $ret['dim']);
if (min(($tmbSize / $srcSize[0]), ($tmbSize / $srcSize[1])) < 1) {
if (!empty($raw->thumbnails)) {
$tmbArr = (array)$raw->thumbnails[0];
if (!empty($tmbArr[$tmb]->url)) {
$ret['url'] = $tmbArr[$tmb]->url;
if ($work = $this->getWorkFile($path)) {
if ($size = @getimagesize($work)) {
$cache['width'] = $size[0];
$cache['height'] = $size[1];
$ret = $size[0] . 'x' . $size[1];
is_file($work) && @unlink($work);
/******************** file/dir content *********************/
* Return files list in directory.
* @param string $path dir path
* @throws elFinderAbortException
* @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
* @param bool $write open file for writing
* @author Dmitry (dio) Levashov
protected function _fopen($path, $mode = 'rb')
if ($mode === 'rb' || $mode === 'r') {
list(, $itemId) = $this->_od_splitPath($path);
'target' => self::API_URL . $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)
$namePath = $this->_joinPath($path, $name);
list($parentId) = $this->_od_splitPath($namePath);
'folder' => (object)array(),
$data = (object)$properties;
$url = self::API_URL . $parentId . '/children';
$curl = $this->_od_prepareCurl($url);
curl_setopt_array($curl, array(
CURLOPT_POSTFIELDS => json_encode($data),
//create the Folder in the Parent
$result = elFinder::curlExec($curl);
$folder = json_decode($result);
return $this->_joinPath($path, $folder->id);
return $this->setError('OneDrive 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)
$path = $this->_joinPath($targetDir, $name);
list(, $parentId) = $this->_od_splitPath($targetDir);
list(, $itemId) = $this->_od_splitPath($source);
$url = self::API_URL . $itemId . '/copy';
if ($parentId === 'root') {
$properties['parentReference'] = (object)array('path' => '/drive/root:');
$properties['parentReference'] = (object)array('id' => (string)$parentId);
$data = (object)$properties;
$curl = $this->_od_prepareCurl($url);
curl_setopt_array($curl, array(
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: Bearer ' . $this->token->data->access_token,
CURLOPT_POSTFIELDS => json_encode($data),
$result = elFinder::curlExec($curl);
if (preg_match('/Location: (.+)/', $result, $m)) {
$curl = curl_init($monUrl);
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
$res = json_decode(elFinder::curlExec($curl));
if (isset($res->status)) {
if ($res->status === 'completed' || $res->status === 'failed') {
} elseif (isset($res->error)) {
return $this->setError('OneDrive error: ' . $res->error->message);
if ($res && isset($res->resourceId)) {
if (isset($res->folder) && isset($this->sessionCache['subdirs'])) {
$this->sessionCache['subdirs'][$targetDir] = true;
return $this->_joinPath($targetDir, $res->resourceId);
return $this->setError('OneDrive error: ' . $e->getMessage());
* Move file into another parent dir.
* Return new file path or false.
* @param string $source source file path
* @param string $name file name
* @author Dmitry (dio) Levashov
protected function _move($source, $targetDir, $name)
list(, $targetParentId) = $this->_od_splitPath($targetDir);
list($sourceParentId, $itemId, $srcParent) = $this->_od_splitPath($source);
if ($targetParentId !== $sourceParentId) {
$properties['parentReference'] = (object)array('id' => (string)$targetParentId);
$url = self::API_URL . $itemId;
$data = (object)$properties;
$curl = $this->_od_prepareCurl($url);
curl_setopt_array($curl, array(
CURLOPT_CUSTOMREQUEST => 'PATCH',
CURLOPT_POSTFIELDS => json_encode($data),
$result = json_decode(elFinder::curlExec($curl));
if ($result && isset($result->id)) {
return $targetDir . '/' . $result->id;
return $this->setError('OneDrive error: ' . $e->getMessage());
* @param string $path file path
* @author Dmitry (dio) Levashov
protected function _unlink($path)
$stat = $this->stat($path);
list(, $itemId) = $this->_od_splitPath($path);
$url = self::API_URL . $itemId;
$curl = $this->_od_prepareCurl($url);
curl_setopt_array($curl, array(
CURLOPT_CUSTOMREQUEST => 'DELETE',
//unlink or delete File or Folder in the Parent
$result = elFinder::curlExec($curl);
return $this->setError('OneDrive error: ' . $e->getMessage());
* @param string $path dir path
* @author Dmitry (dio) Levashov
protected function _rmdir($path)
return $this->_unlink($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 $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->_od_splitPath($path);
if (isset($stat['name'])) {
if (isset($stat['rev']) && strpos($stat['hash'], $this->id) === 0) {
list(, $parentId) = $this->_od_splitPath($path);
if ($stat && isset($stat['size'])) {
return $this->_od_uploadSession($fp, $size, $name, $itemId, $parent, $parentId);
// for unseekable file pointer
if (!elFinder::isSeekableStream($fp)) {
if (stream_copy_to_stream($fp, $tfp, $size? $size : -1) !== false) {
//Create or Update a file
$url = self::API_URL . $parentId . ':/' . rawurlencode($name) . ':/content';
$url = self::API_URL . $itemId . '/content';
$curl = $this->_od_prepareCurl();