Dotclear 2.25
Loading...
Searching...
No Matches
filemanager Class Reference

Files management class. More...

Inheritance diagram for filemanager:
dcMedia

Public Member Functions

 __construct (?string $root, ?string $root_url='')
 
 chdir (?string $dir)
 
 getPwd ()
 
 writable ()
 
 addExclusion ($list)
 
 inFiles (string $file)
 
 getDir ()
 
 getRootDirs ()
 
 uploadFile (string $tmp, string $dest, bool $overwrite=false)
 
 uploadBits (string $name, string $bits)
 
 makeDir (?string $name)
 
 moveFile (?string $src_path, ?string $dst_path)
 
 removeItem (?string $name)
 
 removeFile (?string $file)
 
 removeDir (?string $directory)
 

Data Fields

 $root
 
 $root_url
 
 $dir
 

Protected Member Functions

 isExclude (string $path)
 
 isFileExclude (string $file)
 
 inJail (string $path)
 
 sortHandler (fileItem $a, fileItem $b)
 

Protected Attributes

 $pwd
 
 $exclude_list = []
 
 $exclude_pattern = ''
 

Detailed Description

Files management class.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ?string  $root,
?string  $root_url = '' 
)

Constructor

New filemanage istance. Note that filemanage is a jail in given root path. You won't be able to access files outside $root path with the object's methods.

Parameters
string$rootRoot path
string$root_urlRoot URL

References $root, $root_url, and path\real().

Member Function Documentation

◆ chdir()

chdir ( ?string  $dir)

Change directory

Changes working directory. $dir is relative to instance $root directory.

Parameters
string$dirDirectory

Reimplemented in dcMedia.

References $dir, path\clean(), isExclude(), and path\real().

◆ getPwd()

getPwd ( )

Get working directory

Returns working directory path.

Returns
string

References $pwd.

◆ writable()

writable ( )

Current directory is writable

Returns
bool true if working directory is writable

◆ addExclusion()

addExclusion (   $list)

Add exclusion

Appends an exclusion to exclusions list. $f should be a regexp.

See also
$exclude_list
Parameters
array | string$listExclusion regexp

References path\real().

Referenced by dcMedia\__construct().

◆ isExclude()

isExclude ( string  $path)
protected

Path is excluded

Returns true if path (file or directory) $path is excluded. $path is relative to $root path.

See also
$exclude_list
Parameters
string$pathPath to match
Returns
bool

Referenced by chdir(), and getDir().

◆ isFileExclude()

isFileExclude ( string  $file)
protected

File is excluded

Returns true if file $file is excluded. $file is relative to $root path.

See also
$exclude_pattern
Parameters
string$fileFile to match
Returns
bool

Referenced by dcMedia\fileRecord(), getDir(), dcMedia\updateFile(), uploadBits(), and uploadFile().

◆ inJail()

inJail ( string  $path)
protected

Item in jail

Returns true if file or directory $path is in jail (ie. not outside the $root directory).

Parameters
string$pathPath to match
Returns
bool

References path\real().

Referenced by getDir(), moveFile(), removeDir(), removeFile(), uploadBits(), and uploadFile().

◆ inFiles()

inFiles ( string  $file)

File in files

Returns true if file $file is in files array of $dir.

Parameters
string$fileFile to match
Returns
bool

Referenced by dcMedia\getDir().

◆ getDir()

getDir ( )

Directory list

Creates list of items in working directory and append it to $dir

Uses sortHandler(), fileItem

References $dir, path\clean(), inJail(), isExclude(), and isFileExclude().

◆ getRootDirs()

getRootDirs ( )

Root directories

Returns an array of directory under $root directory.

Uses fileItem

Returns
array

References files\getDirList().

◆ uploadFile()

uploadFile ( string  $tmp,
string  $dest,
bool  $overwrite = false 
)

Upload file

Move $tmp file to its final destination $dest and returns the destination file path.

$dest should be in jail. This method will throw exception if the file cannot be written.

You should first verify upload status, with files::uploadStatus() or PHP native functions.

See also
files::uploadStatus()
Parameters
string$tmpTemporary uploaded file path
string$destDestination file
bool$overwriteOverwrite mode
Returns
string Destination real path

References path\clean(), files\inheritChmod(), inJail(), isFileExclude(), and path\real().

◆ uploadBits()

uploadBits ( string  $name,
string  $bits 
)

Upload file by bits

Creates a new file $name with contents of $bits and return the destination file path.

$name should be in jail. This method will throw exception if file cannot be written.

Parameters
string$nameDestination file
string$bitsDestination file content
Returns
string Destination real path

Reimplemented in dcMedia.

References path\clean(), files\inheritChmod(), inJail(), isFileExclude(), and path\real().

◆ makeDir()

makeDir ( ?string  $name)

New directory

Creates a new directory relative to working directory.

Parameters
string$nameDirectory name

Reimplemented in dcMedia.

References path\clean(), and files\makeDir().

◆ moveFile()

moveFile ( ?string  $src_path,
?string  $dst_path 
)

Move file

Moves a file to a new destination. Both paths are relative to $root.

Parameters
string$src_pathSource file path
string$dst_pathDestination file path

References path\clean(), inJail(), and path\real().

Referenced by dcMedia\updateFile().

◆ removeItem()

removeItem ( ?string  $name)

Remove item

Removes a file or directory which is relative to working directory.

Parameters
string$nameItem to remove

References path\clean(), path\real(), removeDir(), and removeFile().

◆ removeFile()

removeFile ( ?string  $file)

Remove item

Removes a file which is relative to working directory.

Parameters
string$fileFile to remove

Reimplemented in dcMedia.

References path\clean(), inJail(), files\isDeletable(), and path\real().

Referenced by removeItem().

◆ removeDir()

removeDir ( ?string  $directory)

Remove item

Removes a directory which is relative to working directory.

Parameters
string$directoryDirectory to remove

Reimplemented in dcMedia.

References path\clean(), inJail(), files\isDeletable(), and path\real().

Referenced by removeItem().

◆ sortHandler()

sortHandler ( fileItem  $a,
fileItem  $b 
)
protected

SortHandler

This method is called by getDir() to sort files. Can be overrided in inherited classes.

Parameters
fileItem$afileItem object
fileItem$bfileItem object
Returns
int

Field Documentation

◆ $root

$root

Referenced by __construct(), and dcMedia\__construct().

◆ $root_url

$root_url

Referenced by __construct(), and dcMedia\__construct().

◆ $pwd

◆ $exclude_list

$exclude_list = []
protected

◆ $exclude_pattern

$exclude_pattern = ''
protected

◆ $dir

$dir
Initial value:
= [
'dirs' => [],
'files' => [],
]

Referenced by dcMedia\chdir(), chdir(), dcMedia\getDBDirs(), dcMedia\getDir(), getDir(), dcMedia\rebuild(), and dcMedia\rebuildThumbnails().


The documentation for this class was generated from the following file: