PHP Class elFinder

Core class.
Author: Dmitry (dio) Levashov
Author: Troex Nevelin
Author: Alexey Sukhotin
Exibir arquivo Open project: studio-42/elfinder Class Usage Examples

Public Properties

Property Type Description
$defaultMimefile string elFinderVolumeDriver default mime.type file path
$instance object elFinder instance
$locale string elFinder global locale
$maxTargets Max allowed numbar of @var targets (0 - no limit)
$mountErrors array Errors from not mounted volumes
$netDrivers array Network mount drivers
$phpErrors array Errors from PHP
$sessionCacheKey string elFinder global sessionCacheKey
$volumesCnt integer Mounted volumes count Required to create unique volume id

Protected Properties

Property Type Description
$base64encodeSessionData boolean elFinder base64encodeSessionData elFinder save session data as UTF-8 If the session storage mechanism of the system does not allow UTF-8 And it must be true option 'base64encodeSessionData' of elFinder
$callbackWindowURL URL for callback output window for CORS redirect to this URL when callback output
$commands array Commands and required arguments list
$commonTempPath string elFinder common tempraly path
$debug string Send debug to client?
$default elFinderStorageDriver Default root (storage)
$listeners array Commands listeners
$loaded boolean Is elFinder init correctly?
$maxArcFilesSize integer Max allowed archive files size (0 - no limit)
$netVolumesSessionKey string Session key of net mount volumes
$optionsNetVolumes array Additional volume root options for network mounting volume
$plugins array Plugins instance
$session elFinderSessionInterface elFinder session wrapper object
$sessionCloseEarlier boolean Call session_write_close() before exec command?
$sessionUseCmds array SESSION use commands @see __construct()
$time string script work time for debug
$timeout integer session expires timeout
$uploadDebug string undocumented class variable
$uploadTempPath string Temp dir path for Upload
$version string API version number
$volumes array Storages (root dirs)

Public Methods

Method Description
__construct ( $opts ) Constructor
bind ( $cmd, $handler ) : elFinder Add handler to elFinder command
commandArgsList ( $cmd ) : array Return command required arguments info
commandExists ( $cmd ) : boolean Return true if command exists
curlExec ( resource $curl, array $options = [], array $headers = [] ) : mixed Call curl_exec() with supported redirect on safe_mode or open_basedir
error ( ) : array Normalize error messages
exec ( string $cmd, array $args ) : array Exec command and return result
extendTimeLimit ( Int $time = null ) : void Extend PHP execution time limit
getConnectorUrl ( ) : string Get script url.
getIniBytes ( string $iniName = '', string $val = '' ) : number Return bytes from php.ini value
getSession ( ) : object Return elFinder session wrapper instance
getStaticVar ( $key ) : mixed | null Return elFinder static variable
getStreamByUrl ( array $data, number $redirectLimit = 5 ) : resource | boolean Get stream resource pointer by URL
getVolume ( $hash ) : elFinderStorageDriver Return root - file's owner (public func of volume())
isAnimationGif ( string $path ) : boolean Return Is Animation Gif
isSeekableStream ( resource $resource ) : boolean Return Is seekable stream resource
loaded ( ) : boolean Return true if fm init correctly
phpErrorHandler ( integer $errno, string $errstr, string $errfile, integer $errline ) : void | boolean PHP error handler, catch error types only E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE
realpath ( string $hash ) : string Return file real path
rewind ( resource $resource ) : void Rewind stream resource
sessionDataDecode ( mixed &$var, boolean $checkIs = null ) : boolean | mixed base64_decode and unserialize of session data (If needed)
sessionDataEncode ( mixed $var ) : mixed | string serialize and base64_encode of session data (If needed)
sessionWrite ( ) : void Call session_write_close() if session is restarted
unbind ( $cmd, $handler ) : elFinder Remove event (command exec) handler
updateNetVolumeOption ( string $netKey, string $optionKey, mixed $val ) Update sesstion value of a NetVolume option
version ( ) : string Return version (api) number

Protected Methods

Method Description
archive ( array $args ) : array Create archive
callback ( $args ) Output callback result with JavaScript that control elFinder or HTTP redirect to callbackWindowURL
chmod ( $args ) : array chmod
curl_get_contents ( string &$url, integer $timeout, integer $redirect_max, string $ua, resource $outfp ) : string Get remote contents with cURL
detectFileExtension ( string $path ) : string Detect file type extension by local path
dim ( array $args ) : array Return image dimensions
duplicate ( array $args ) : array Duplicate file - create copy with "copy %d" suffix
ensureDirsRecursively ( object $volume, string $target, string $dirs, string $path = '' ) : array | false Ensure directories recursively
extract ( array $args ) : array Extract files from archive
file ( $args ) : array Required to output file in browser when volume URL is not set Return array contains opened file pointer, root itself and required headers
filter ( array $files ) : array Remove from files list hidden files and files with required mime types
fsock_get_contents ( string &$url, integer $timeout, integer $redirect_max, string $ua, resource $outfp ) : string Get remote contents with fsockopen()
get ( array $args ) : array Return file content
getNetVolumeUniqueId ( array $netVolumes = null, string $prefix = 'nm' ) : string | false Return Network mount volume unique ID
getNetVolumes ( ) : array Return network volumes config.
getPluginInstance ( string $name, array $opts = [] ) : object | boolean Get plugin instance & set to $this->plugins
get_remote_contents ( string &$url, integer $timeout = 30, integer $redirect_max = 5, string $ua = 'Mozilla/5.0', resource $fp = null ) : string Get remote contents
hashes ( array $files ) : array Return fils hashes list
info ( array $args ) : array Return file info (used by client "places" ui)
ls ( $args ) : array Return dir files names list
mkdir ( $args ) : array Create directory
mkfile ( $args ) : array Create empty file
netmount ( $args )
open ( $args ) : array "Open" directory Return array with following elements - cwd - opened dir info - files - opened dir content [and dirs tree if $args[tree]] - api - api version (if $args[init]) - uplMaxSize - if $args[init] - error - on failed
parents ( $args ) : array Return parents dir for required directory
parse_data_scheme ( string $str, array $extTable ) : array Parse Data URI scheme
paste ( $args ) : array Copy/move files into new destination
put ( $args ) : array Save content into text file
removeNetVolume ( string $key, object $volume ) : boolean Remove netmount volume
rename ( array $args ) : array Rename file
resize ( $args ) : array Resize image
rm ( $args ) : array Remove dirs/files
saveNetVolumes ( array $volumes ) : void Save network volumes config.
search ( array $args ) : array Search files
size ( $args ) : array Count total files size
tmb ( $args ) : array Return new created thumbnails list
toArray ( array $data ) : array Return files info array
tree ( $args ) : array Return subdirs for required directory
upload ( $args ) : array Save uploaded files
url ( array $args ) : array Return content URL
utime ( )
volume ( $hash ) : elFinderStorageDriver Return root - file's owner
zipdl ( $args ) : array Download files/folders as an archive file

Private Methods

Method Description
checkChunkedFile ( string $tmpname, string $chunk, string $cid, string $tempDir, null $volume = null ) : array Check chunked upload files
getTempDir ( string $volumeTempPath = null ) : string Get temporary directory path
session_expires ( )

Method Details

__construct() public method

Constructor
Author: Dmitry (dio) Levashov
public __construct ( $opts )

archive() protected method

Create archive
Author: Dmitry (dio) Levashov,
Author: Alexey Sukhotin
protected archive ( array $args ) : array
$args array command arguments
return array

bind() public method

Add handler to elFinder command
Author: Dmitry (dio) Levashov
public bind ( $cmd, $handler ) : elFinder
return elFinder

callback() protected method

Output callback result with JavaScript that control elFinder or HTTP redirect to callbackWindowURL
Author: Naoki Sawada
protected callback ( $args )

chmod() protected method

chmod
Author: David Bartle
protected chmod ( $args ) : array
return array

commandArgsList() public method

Return command required arguments info
Author: Dmitry (dio) Levashov
public commandArgsList ( $cmd ) : array
return array

commandExists() public method

Return true if command exists
Author: Dmitry (dio) Levashov
public commandExists ( $cmd ) : boolean
return boolean

curlExec() public static method

Call curl_exec() with supported redirect on safe_mode or open_basedir
Author: Naoki Sawada
public static curlExec ( resource $curl, array $options = [], array $headers = [] ) : mixed
$curl resource
$options array
$headers array
return mixed

curl_get_contents() protected method

Get remote contents with cURL
Author: Naoki Sawada
protected curl_get_contents ( string &$url, integer $timeout, integer $redirect_max, string $ua, resource $outfp ) : string
$url string target url
$timeout integer timeout (sec)
$redirect_max integer redirect max count
$ua string
$outfp resource
return string or bool(false)

detectFileExtension() protected method

Detect file type extension by local path
Author: Naoki Sawada
protected detectFileExtension ( string $path ) : string
$path string Local path
return string file type extension with dot

dim() protected method

Return image dimensions
Author: Dmitry (dio) Levashov
protected dim ( array $args ) : array
$args array command arguments
return array

duplicate() protected method

Duplicate file - create copy with "copy %d" suffix
Author: Dmitry (dio) Levashov
protected duplicate ( array $args ) : array
$args array command arguments
return array

ensureDirsRecursively() protected method

Ensure directories recursively
Author: Naoki Sawada
protected ensureDirsRecursively ( object $volume, string $target, string $dirs, string $path = '' ) : array | false
$volume object Volume object
$target string Target hash
$dirs string Array of directory tree to ensure
$path string Relative path form target hash
return array | false array('stats' => array([stat of maked directory]), 'hashes' => array('[path]' => '[hash]'))

error() public method

Normalize error messages
Author: Dmitry (dio) Levashov
public error ( ) : array
return array

exec() public method

Exec command and return result
Author: Dmitry (dio) Levashov
public exec ( string $cmd, array $args ) : array
$cmd string command name
$args array command arguments
return array

extendTimeLimit() public static method

Extend PHP execution time limit
public static extendTimeLimit ( Int $time = null ) : void
$time Int
return void

extract() protected method

Extract files from archive
Author: Dmitry (dio) Levashov,
Author: Alexey Sukhotin
protected extract ( array $args ) : array
$args array command arguments
return array

file() protected method

Required to output file in browser when volume URL is not set Return array contains opened file pointer, root itself and required headers
Author: Dmitry (dio) Levashov
protected file ( $args ) : array
return array

filter() protected method

Remove from files list hidden files and files with required mime types
Author: Dmitry (dio) Levashov
protected filter ( array $files ) : array
$files array files info
return array

fsock_get_contents() protected method

Get remote contents with fsockopen()
Author: Naoki Sawada
protected fsock_get_contents ( string &$url, integer $timeout, integer $redirect_max, string $ua, resource $outfp ) : string
$url string url
$timeout integer timeout (sec)
$redirect_max integer redirect max count
$ua string
$outfp resource
return string or bool(false)

get() protected method

Return file content
Author: Dmitry (dio) Levashov
protected get ( array $args ) : array
$args array command arguments
return array

getConnectorUrl() public static method

Get script url.
Author: Naoki Sawada
public static getConnectorUrl ( ) : string
return string full URL

getIniBytes() public static method

Return bytes from php.ini value
public static getIniBytes ( string $iniName = '', string $val = '' ) : number
$iniName string
$val string
return number

getNetVolumeUniqueId() protected method

Return Network mount volume unique ID
Author: Naoki Sawada
protected getNetVolumeUniqueId ( array $netVolumes = null, string $prefix = 'nm' ) : string | false
$netVolumes array Saved netvolumes array
$prefix string Id prefix
return string | false

getNetVolumes() protected method

Return network volumes config.
Author: Dmitry (dio) Levashov
protected getNetVolumes ( ) : array
return array

getPluginInstance() protected method

Get plugin instance & set to $this->plugins
Author: Naoki Sawada
protected getPluginInstance ( string $name, array $opts = [] ) : object | boolean
$name string Plugin name (dirctory name)
$opts array Plugin options (optional)
return object | boolean | bool Plugin object instance Or false

getSession() public method

Return elFinder session wrapper instance
public getSession ( ) : object
return object elFinderSessionInterface

getStaticVar() public static method

Return elFinder static variable
public static getStaticVar ( $key ) : mixed | null
$key
return mixed | null

getStreamByUrl() public static method

Get stream resource pointer by URL
Author: Naoki Sawada
public static getStreamByUrl ( array $data, number $redirectLimit = 5 ) : resource | boolean
$data array array('target'=>'URL', 'headers' => array())
$redirectLimit number
return resource | boolean

getVolume() public method

Return root - file's owner (public func of volume())
Author: Naoki Sawada
public getVolume ( $hash ) : elFinderStorageDriver
return elFinderStorageDriver

get_remote_contents() protected method

Get remote contents
Author: Naoki Sawada
protected get_remote_contents ( string &$url, integer $timeout = 30, integer $redirect_max = 5, string $ua = 'Mozilla/5.0', resource $fp = null ) : string
$url string target url
$timeout integer timeout (sec)
$redirect_max integer redirect max count
$ua string
$fp resource
return string or bool(false)

hashes() protected method

Return fils hashes list
Author: Dmitry (dio) Levashov
protected hashes ( array $files ) : array
$files array files info
return array

info() protected method

Return file info (used by client "places" ui)
Author: Dmitry Levashov
protected info ( array $args ) : array
$args array command arguments
return array

isAnimationGif() public static method

Return Is Animation Gif
public static isAnimationGif ( string $path ) : boolean
$path string server local path of target image
return boolean

isSeekableStream() public static method

Return Is seekable stream resource
public static isSeekableStream ( resource $resource ) : boolean
$resource resource
return boolean

loaded() public method

Return true if fm init correctly
Author: Dmitry (dio) Levashov
public loaded ( ) : boolean
return boolean

ls() protected method

Return dir files names list
Author: Dmitry (dio) Levashov
protected ls ( $args ) : array
return array

mkdir() protected method

Create directory
Author: Dmitry (dio) Levashov
protected mkdir ( $args ) : array
return array

mkfile() protected method

Create empty file
Author: Dmitry (dio) Levashov
protected mkfile ( $args ) : array
return array

netmount() protected method

protected netmount ( $args )

open() protected method

"Open" directory Return array with following elements - cwd - opened dir info - files - opened dir content [and dirs tree if $args[tree]] - api - api version (if $args[init]) - uplMaxSize - if $args[init] - error - on failed
Author: Dmitry (dio) Levashov
protected open ( $args ) : array
return array

parents() protected method

Return parents dir for required directory
Author: Dmitry (dio) Levashov
protected parents ( $args ) : array
return array

parse_data_scheme() protected method

Parse Data URI scheme
Author: Naoki Sawada
protected parse_data_scheme ( string $str, array $extTable ) : array
$str string
$extTable array
return array

paste() protected method

Copy/move files into new destination
Author: Dmitry (dio) Levashov
protected paste ( $args ) : array
return array

phpErrorHandler() public static method

PHP error handler, catch error types only E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE
public static phpErrorHandler ( integer $errno, string $errstr, string $errfile, integer $errline ) : void | boolean
$errno integer
$errstr string
$errfile string
$errline integer
return void | boolean

put() protected method

Save content into text file
Author: Dmitry (dio) Levashov
protected put ( $args ) : array
$args
return array

realpath() public method

Return file real path
Author: Dmitry (dio) Levashov
public realpath ( string $hash ) : string
$hash string file hash
return string

removeNetVolume() protected method

Remove netmount volume
protected removeNetVolume ( string $key, object $volume ) : boolean
$key string netvolume key
$volume object volume driver instance
return boolean

rename() protected method

Rename file
Author: Dmitry (dio) Levashov
protected rename ( array $args ) : array
$args array
return array

resize() protected method

Resize image
Author: Dmitry (dio) Levashov
Author: Alexey Sukhotin
protected resize ( $args ) : array
return array

rewind() public static method

Rewind stream resource
public static rewind ( resource $resource ) : void
$resource resource
return void

rm() protected method

Remove dirs/files
Author: Dmitry (dio) Levashov
protected rm ( $args ) : array
return array

saveNetVolumes() protected method

Save network volumes config.
Author: Dmitry (dio) Levashov
protected saveNetVolumes ( array $volumes ) : void
$volumes array volumes config
return void

sessionDataDecode() public static method

base64_decode and unserialize of session data (If needed)
Deprecation:
Author: Naoki Sawada
public static sessionDataDecode ( mixed &$var, boolean $checkIs = null ) : boolean | mixed
$var mixed target variable
$checkIs boolean data type for check (array|string|object|int)
return boolean | mixed

sessionDataEncode() public static method

serialize and base64_encode of session data (If needed)
Deprecation:
Author: Naoki Sawada
public static sessionDataEncode ( mixed $var ) : mixed | string
$var mixed target variable
return mixed | string

sessionWrite() public static method

Call session_write_close() if session is restarted
Deprecation:
public static sessionWrite ( ) : void
return void

size() protected method

Count total files size
Author: Dmitry (dio) Levashov
protected size ( $args ) : array
return array

tmb() protected method

Return new created thumbnails list
Author: Dmitry (dio) Levashov
protected tmb ( $args ) : array
return array

toArray() protected method

Return files info array
Author: Dmitry (dio) Levashov
protected toArray ( array $data ) : array
$data array one file info or files info
return array

tree() protected method

Return subdirs for required directory
Author: Dmitry (dio) Levashov
protected tree ( $args ) : array
return array

unbind() public method

Remove event (command exec) handler
Author: Dmitry (dio) Levashov
public unbind ( $cmd, $handler ) : elFinder
return elFinder

updateNetVolumeOption() public method

Update sesstion value of a NetVolume option
public updateNetVolumeOption ( string $netKey, string $optionKey, mixed $val )
$netKey string
$optionKey string
$val mixed

upload() protected method

Save uploaded files
Author: Dmitry (dio) Levashov
protected upload ( $args ) : array
return array

url() protected method

Return content URL
Author: Naoki Sawada
protected url ( array $args ) : array
$args array command arguments
return array

utime() protected method

protected utime ( )

version() public method

Return version (api) number
Author: Dmitry (dio) Levashov
public version ( ) : string
return string

volume() protected method

Return root - file's owner
Author: Dmitry (dio) Levashov
protected volume ( $hash ) : elFinderStorageDriver
return elFinderStorageDriver

zipdl() protected method

1st: Return srrsy contains download archive file info 2nd: Return array contains opened file pointer, root itself and required headers
Author: Naoki Sawada
protected zipdl ( $args ) : array
return array

Property Details

$base64encodeSessionData protected_oe static_oe property

elFinder base64encodeSessionData elFinder save session data as UTF-8 If the session storage mechanism of the system does not allow UTF-8 And it must be true option 'base64encodeSessionData' of elFinder
protected static bool $base64encodeSessionData
return boolean

$callbackWindowURL protected_oe property

URL for callback output window for CORS redirect to this URL when callback output
protected $callbackWindowURL

$commands protected_oe property

Commands and required arguments list
protected array $commands
return array

$commonTempPath protected_oe static_oe property

elFinder common tempraly path
protected static string $commonTempPath
return string

$debug protected_oe property

Send debug to client?
protected string $debug
return string

$default protected_oe property

Default root (storage)
protected elFinderStorageDriver $default
return elFinderStorageDriver

$defaultMimefile public_oe static_oe property

elFinderVolumeDriver default mime.type file path
public static string $defaultMimefile
return string

$instance public_oe static_oe property

elFinder instance
public static object $instance
return object

$listeners protected_oe property

Commands listeners
protected array $listeners
return array

$loaded protected_oe property

Is elFinder init correctly?
protected bool $loaded
return boolean

$locale public_oe static_oe property

elFinder global locale
public static string $locale
return string

$maxArcFilesSize protected_oe property

Max allowed archive files size (0 - no limit)
protected int $maxArcFilesSize
return integer

$maxTargets public_oe property

Max allowed numbar of @var targets (0 - no limit)
public $maxTargets

$mountErrors public_oe property

Errors from not mounted volumes
public array $mountErrors
return array

$netDrivers public_oe static_oe property

Network mount drivers
public static array $netDrivers
return array

$netVolumesSessionKey protected_oe property

Session key of net mount volumes
Deprecation:
protected string $netVolumesSessionKey
return string

$optionsNetVolumes protected_oe property

Additional volume root options for network mounting volume
protected array $optionsNetVolumes
return array

$phpErrors public_oe static_oe property

Errors from PHP
public static array $phpErrors
return array

$plugins protected_oe property

Plugins instance
protected array $plugins
return array

$session protected_oe property

elFinder session wrapper object
protected elFinderSessionInterface $session
return elFinderSessionInterface

$sessionCacheKey public_oe static_oe property

elFinder global sessionCacheKey
Deprecation:
public static string $sessionCacheKey
return string

$sessionCloseEarlier protected_oe property

Call session_write_close() before exec command?
protected bool $sessionCloseEarlier
return boolean

$sessionUseCmds protected_oe property

SESSION use commands @see __construct()
protected array $sessionUseCmds
return array

$time protected_oe property

script work time for debug
protected string $time
return string

$timeout protected_oe property

session expires timeout
protected int $timeout
return integer

$uploadDebug protected_oe property

undocumented class variable
protected string $uploadDebug
return string

$uploadTempPath protected_oe property

Temp dir path for Upload
protected string $uploadTempPath
return string

$version protected_oe property

API version number
protected string $version
return string

$volumes protected_oe property

Storages (root dirs)
protected array $volumes
return array

$volumesCnt public_oe static_oe property

Mounted volumes count Required to create unique volume id
public static int $volumesCnt
return integer