PHP Класс CFile

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__toString ( ) : string Returns filesystem object filepath.
copy ( string $dest ) : CFile | boolean Copies the current filesystem object to specified destination.
create ( ) : CFile | boolean Creates empty file if the current file doesn't exist.
createDir ( integer | string $permissions = 492, null | string $directory = null ) : boolean | CFile Creates empty directory defined either through {@link set} or through the $directory parameter.
delete ( boolean $purge = True ) : boolean Deletes the current filesystem object.
download ( null | string $fake_name = null, boolean $server_handled = False, null | string $content_type = null ) : boolean | null Alias for {@link send}.
getBasename ( ) : string Returns the current file basename (file name plus extension) from $_basename property set by {@link pathInfo} (e.g.: 'myfile.htm' for '/var/www/htdocs/files/myfile.htm').
getContents ( boolean $recursive = False, string $filter = null ) : string | array | boolean Returns the current filesystem object contents.
getDirname ( ) : string Returns the current file directory name (without final slash) from $_dirname property set by {@link pathInfo} (e.g.: '/var/www/htdocs/files' for '/var/www/htdocs/files/myfile.htm')
getExists ( ) : boolean Tests current filesystem object existence and returns boolean (see {@link exists}).
getExtension ( ) : string Returns the current file extension from $_extension property set by {@link pathInfo} (e.g.: 'htm' for '/var/www/htdocs/files/myfile.htm').
getFilename ( ) : string Returns the current file name (without extension) from $_filename property set by {@link pathInfo} (e.g.: 'myfile' for '/var/www/htdocs/files/myfile.htm')
getGroup ( boolean $get_name = True ) : integer | string | boolean Returns group of current filesystem object (UNIX systems).
getInstance ( string $filepath, string $class_name = __CLASS__ ) : object Returns the instance of CFile for the specified file.
getIsDir ( ) : boolean Returns filesystem object type for the current file (see {@link pathInfo}).
getIsEmpty ( ) : boolean Returns filesystem object has-contents flag.
getIsFile ( ) : boolean Returns filesystem object type for the current file (see {@link pathInfo}).
getIsUploaded ( ) : boolean Tells whether file is uploaded through a web form.
getMimeType ( ) : string | boolean Returns the MIME type of the current file.
getMimeTypeByExtension ( ) : string Determines the MIME type based on the extension of the current file.
getOwner ( boolean $get_name = True ) : integer | string | boolean Returns owner of current filesystem object (UNIX systems).
getPermissions ( ) : string Returns permissions of current filesystem object (UNIX systems).
getReadable ( ) : boolean Tests whether the current filesystem object is readable and returns boolean.
getRealPath ( string $dir_separator = DIRECTORY_SEPARATOR ) : string Returns real filesystem object path figured by script (see {@link realPath}) on the basis of user supplied $_filepath.
getRelativePath ( ) : string Returns relative filesystem object path figured by script on the basis of $_realpath
getSize ( string | boolean $format = '0.00' ) : string | integer Returns size of current filesystem object.
getTimeCreated ( ) : integer Returns the current file created time. Works on Windows System only! Returned Unix timestamp could be passed to php date() function.
getTimeModified ( ) : integer Returns the current file last modified time.
getWriteable ( ) : boolean Tests whether the current filesystem object is readable and returns boolean.
move ( string $dest ) : CFile | boolean Alias for {@link rename}.
purge ( null | string $path = null ) : boolean | CFile Purges (makes empty) the current filesystem object.
rename ( string $dest ) : CFile | boolean Renames/moves the current filesystem object to specified destination.
send ( null | string $fake_name = null, boolean $server_handled = False, null | string $content_type = null ) : boolean | null Sends the current file to browser as a download with real or faked file name.
set ( string $filepath, boolean $greedy = False ) : object Basic CFile method. Sets CFile object to work with specified filesystem object.
setBasename ( null | string $basename = null ) : boolean | CFile Sets basename for the current file.
setContents ( string $contents = null, boolean $autocreate = True, integer $flags ) : CFile | boolean Writes contents (data) into the current file.
setExtension ( null | boolean | string $extension = False ) : boolean | CFile Sets the current file extension.
setFilename ( null | string $filename = null ) : boolean | CFile Sets the current file name.
setGroup ( string | integer $group, boolean $recursive = False ) : CFile | boolean Sets the current filesystem object group, updates $_group property on success.
setOwner ( string | integer $owner, boolean $recursive = False ) : CFile | boolean Sets the current filesystem object owner, updates $_owner property on success.
setPermissions ( string $permissions, boolean $recursive = False ) : CFile | boolean Sets the current filesystem object permissions, updates $_permissions property on success.

Защищенные методы

Метод Описание
addLog ( string $message, string $level = 'info' ) Logs a message.
formatNumber ( number $number, string $format ) : string Formats a given number into a given format and returns it.
getPathOfAlias ( string $alias ) : boolean | string Returns filepath for a given alias.

Приватные методы

Метод Описание
close ( ) Closes (if opened) the current file pointer.
dirContents ( null | string $directory = null, boolean $recursive = False, null | string $filter = null ) : array Gets directory contents (descendant files and folders).
dirSize ( ) : integer Calculates the current directory size recursively fetching sizes of all descendant files.
exists ( ) : boolean Base filesystem object existence resolving method.
filterPassed ( string $str, array $filter ) : boolean Applies an array of filter rules to the string representing filepath.
formatFileSize ( integer $bytes, string $format = '0.00' ) : string Base filesystem object size format method.
open ( string $mode ) : boolean | CFile Opens (if not already opened) the current file using certain mode.
pathInfo ( ) Populates basic CFile properties (i.e. 'Dirname', 'Basename', etc.) using values resolved by pathinfo() php function.
realPath ( string $supplied_path, string $dir_separator = DIRECTORY_SEPARATOR ) : string Base real filesystem object path resolving method.
resolveDestPath ( string $dest ) : string Resolves destination path for the current filesystem object.

Описание методов

__toString() публичный метод

Returns filesystem object filepath.
public __toString ( ) : string
Результат string

addLog() защищенный метод

Logs a message.
protected addLog ( string $message, string $level = 'info' )
$message string Message to be logged
$level string Level of the message (e.g. 'trace', 'warning', 'error', 'info', see CLogger constants definitions)

copy() публичный метод

Destination path supplied by user resolved to real destination path with {@link resolveDestPath}
public copy ( string $dest ) : CFile | boolean
$dest string Destination path for the current filesystem object to be copied to
Результат CFile | boolean New CFile object for newly created filesystem object on success, 'False' on fail.

create() публичный метод

Creates empty file if the current file doesn't exist.
public create ( ) : CFile | boolean
Результат CFile | boolean Updated the current CFile object on success, 'False' on fail.

createDir() публичный метод

Creates empty directory defined either through {@link set} or through the $directory parameter.
public createDir ( integer | string $permissions = 492, null | string $directory = null ) : boolean | CFile
$permissions integer | string Access permissions for the directory
$directory null | string Parameter used to create directory other than supplied by {@link set} method of the CFile
Результат boolean | CFile Updated the current CFile object on success, 'False' on fail.

delete() публичный метод

For folders purge parameter can be supplied.
public delete ( boolean $purge = True ) : boolean
$purge boolean If 'True' folder would be deleted with all the descendants
Результат boolean 'True' if successfully deleted, 'False' on fail

download() публичный метод

Alias for {@link send}.
public download ( null | string $fake_name = null, boolean $server_handled = False, null | string $content_type = null ) : boolean | null
$fake_name null | string
$server_handled boolean
$content_type null | string
Результат boolean | null

formatNumber() защищенный метод

See {@link CNumberFormatter}.
protected formatNumber ( number $number, string $format ) : string
$number number
$format string
Результат string

getBasename() публичный метод

Returns the current file basename (file name plus extension) from $_basename property set by {@link pathInfo} (e.g.: 'myfile.htm' for '/var/www/htdocs/files/myfile.htm').
public getBasename ( ) : string
Результат string Current file basename

getContents() публичный метод

Reads data from filesystem object if it is a regular file. List files and directories inside the specified path if filesystem object is a directory.
public getContents ( boolean $recursive = False, string $filter = null ) : string | array | boolean
$recursive boolean If True method would return all directory descendants.
$filter string Filter to be applied to all directory descendants. Could be a string, or an array of strings (perl regexp are supported, if started with '~').
Результат string | array | boolean Data read for files, or directory contents names array. False on fail.

getDirname() публичный метод

Returns the current file directory name (without final slash) from $_dirname property set by {@link pathInfo} (e.g.: '/var/www/htdocs/files' for '/var/www/htdocs/files/myfile.htm')
public getDirname ( ) : string
Результат string Current file directory name

getExists() публичный метод

If $_exists property is set, returned value is read from that property.
public getExists ( ) : boolean
Результат boolean 'True' if file exists, otherwise 'False'

getExtension() публичный метод

Returns the current file extension from $_extension property set by {@link pathInfo} (e.g.: 'htm' for '/var/www/htdocs/files/myfile.htm').
public getExtension ( ) : string
Результат string Current file extension without the leading dot

getFilename() публичный метод

Returns the current file name (without extension) from $_filename property set by {@link pathInfo} (e.g.: 'myfile' for '/var/www/htdocs/files/myfile.htm')
public getFilename ( ) : string
Результат string Current file name

getGroup() публичный метод

Returned value depends upon $getName parameter value. If $_group property is set, returned value is read from that property.
public getGroup ( boolean $get_name = True ) : integer | string | boolean
$get_name boolean Defaults to 'True', meaning that group name instead of ID should be returned.
Результат integer | string | boolean Group name, or ID if $getName set to 'False'

getInstance() публичный статический метод

Returns the instance of CFile for the specified file.
public static getInstance ( string $filepath, string $class_name = __CLASS__ ) : object
$filepath string Path to file specified by user.
$class_name string Class name to spawn object for.
Результат object CFile instance

getIsDir() публичный метод

Tells whether filesystem object is a directory.
public getIsDir ( ) : boolean
Результат boolean 'True' if filesystem object is a directory, otherwise 'False'

getIsEmpty() публичный метод

Directory considered empty if it doesn't contain descendants. File considered empty if its size is 0 bytes.
public getIsEmpty ( ) : boolean
Результат boolean 'True' if file is a directory, otherwise 'False'

getIsFile() публичный метод

Tells whether filesystem object is a regular file.
public getIsFile ( ) : boolean
Результат boolean 'True' if filesystem object is a regular file, otherwise 'False'

getIsUploaded() публичный метод

Tells whether file is uploaded through a web form.
public getIsUploaded ( ) : boolean
Результат boolean 'True' if file is uploaded, otherwise 'False'

getMimeType() публичный метод

If $_mime_type property is set, returned value is read from that property. This method will attempt the following approaches in order: 1. finfo 2. mime_content_type 3. {@link getMimeTypeByExtension} This method works only for files.
public getMimeType ( ) : string | boolean
Результат string | boolean the MIME type on success, 'False' on fail.

getMimeTypeByExtension() публичный метод

This method will use a local map between extension name and MIME type. This method works only for files.
public getMimeTypeByExtension ( ) : string
Результат string the MIME type. False is returned if the MIME type cannot be determined.

getOwner() публичный метод

Returned value depends upon $getName parameter value. If $_owner property is set, returned value is read from that property.
public getOwner ( boolean $get_name = True ) : integer | string | boolean
$get_name boolean Defaults to 'True', meaning that owner name instead of ID should be returned.
Результат integer | string | boolean Owner name, or ID if $getName set to 'False'

getPathOfAlias() защищенный метод

Returns filepath for a given alias.
protected getPathOfAlias ( string $alias ) : boolean | string
$alias string
Результат boolean | string

getPermissions() публичный метод

If $_permissions property is set, returned value is read from that property.
public getPermissions ( ) : string
Результат string Filesystem object permissions in octal format (i.e. '0755')

getReadable() публичный метод

If $_readable property is set, returned value is read from that property.
public getReadable ( ) : boolean
Результат boolean 'True' if filesystem object is readable, otherwise 'False'

getRealPath() публичный метод

If $_realpath property is set, returned value is read from that property.
public getRealPath ( string $dir_separator = DIRECTORY_SEPARATOR ) : string
$dir_separator string Directory separator char (depends upon OS)
Результат string Real file path

getRelativePath() публичный метод

Returns relative filesystem object path figured by script on the basis of $_realpath
public getRelativePath ( ) : string
Результат string Relative file path

getSize() публичный метод

Returned value depends upon $format parameter value. If $_size property is set, returned value is read from that property. Uses {@link dirSize} method for directory size calculation.
public getSize ( string | boolean $format = '0.00' ) : string | integer
$format string | boolean Number format or 'False'
Результат string | integer Filesystem object size formatted (e.g.: '70.4 KB') or in bytes (e.g.: '72081') if $format set to 'False'

getTimeCreated() публичный метод

Returns the current file created time. Works on Windows System only! Returned Unix timestamp could be passed to php date() function.
public getTimeCreated ( ) : integer
Результат integer created at time Unix timestamp (e.g.: '1213760802')

getTimeModified() публичный метод

Returned Unix timestamp could be passed to php date() function.
public getTimeModified ( ) : integer
Результат integer Last modified time Unix timestamp (e.g.: '1213760802')

getWriteable() публичный метод

If $_writeable property is set, returned value is read from that property.
public getWriteable ( ) : boolean
Результат boolean 'True' if filesystem object is writeable, otherwise 'False'

move() публичный метод

Alias for {@link rename}.
public move ( string $dest ) : CFile | boolean
$dest string
Результат CFile | boolean

purge() публичный метод

If the current filesystem object is a file its contents set to ''. If the current filesystem object is a directory all its descendants are deleted.
public purge ( null | string $path = null ) : boolean | CFile
$path null | string Filesystem path to object to purge.
Результат boolean | CFile Current CFile object on success, 'False' on fail.

rename() публичный метод

Destination path supplied by user resolved to real destination path with {@link resolveDestPath}
public rename ( string $dest ) : CFile | boolean
$dest string Destination path for the current filesystem object to be renamed/moved to
Результат CFile | boolean Updated current CFile object on success, 'False' on fail.

send() публичный метод

Browser caching is prevented. This method works only for files.
public send ( null | string $fake_name = null, boolean $server_handled = False, null | string $content_type = null ) : boolean | null
$fake_name null | string New filename (e.g.: 'myfileFakedName.htm')
$server_handled boolean Whether file contents delivery is handled by server internals (cf. when file contents is read and sent by php). E.g.: lighttpd and Apache with mod-sendfile can use X-Senfile header to speed up file delivery blazingly. Note: If you want to serve big or even huge files you are definetly advised to turn this option on and setup your server software appropriately, if not to say that it is your only alternative :).
$content_type null | string Should be used to override content type on demand.
Результат boolean | null Returns bool or outputs file contents with headers.

set() публичный метод

Essentially path supplied by user is resolved into real path (see {@link getRealPath}), all the other property getting methods should use that real path. Uploaded files are supported through {@link CUploadedFile} Yii class. Path aliases are supported through {@link getPathOfAlias} Yii method.
public set ( string $filepath, boolean $greedy = False ) : object
$filepath string Path to the file specified by user, if not set exception is raised
$greedy boolean If True file properties (such as 'Size', 'Owner', 'Permission', etc.) would be autoloaded
Результат object CFile instance for the specified filesystem object

setBasename() публичный метод

Lazy wrapper for {@link rename}. This method works only for files.
public setBasename ( null | string $basename = null ) : boolean | CFile
$basename null | string New file basename (e.g.: 'mynewfile.txt')
Результат boolean | CFile Current CFile object on success, 'False' on fail.

setContents() публичный метод

This method works only for files.
public setContents ( string $contents = null, boolean $autocreate = True, integer $flags ) : CFile | boolean
$contents string Contents to be written
$autocreate boolean If 'True' file will be created automatically
$flags integer Flags for file_put_contents(). E.g.: FILE_APPEND to append data to file instead of overwriting.
Результат CFile | boolean Current CFile object on success, 'False' on fail.

setExtension() публичный метод

If new extension is 'null' or 'False' current file extension is dropped. Lazy wrapper for {@link rename}. This method works only for files.
public setExtension ( null | boolean | string $extension = False ) : boolean | CFile
$extension null | boolean | string New file extension (e.g.: 'txt'). Pass null to drop current extension.
Результат boolean | CFile Current CFile object on success, 'False' on fail.

setFilename() публичный метод

Lazy wrapper for {@link rename}. This method works only for files.
public setFilename ( null | string $filename = null ) : boolean | CFile
$filename null | string New file name (e.g.: 'mynewfile')
Результат boolean | CFile Current CFile object on success, 'False' on fail.

setGroup() публичный метод

For POSIX systems. Asserts that group exists before process if posix_ functions are available.
public setGroup ( string | integer $group, boolean $recursive = False ) : CFile | boolean
$group string | integer New group name or ID
$recursive boolean Apply group to directory contents flag.
Результат CFile | boolean Current CFile object on success, 'False' on fail.

setOwner() публичный метод

For POSIX systems. Asserts that user exists before process if posix_ functions are available.
public setOwner ( string | integer $owner, boolean $recursive = False ) : CFile | boolean
$owner string | integer New owner name or ID
$recursive boolean Apply owner to directory contents flag.
Результат CFile | boolean Current CFile object on success, 'False' on fail.

setPermissions() публичный метод

For UNIX systems.
public setPermissions ( string $permissions, boolean $recursive = False ) : CFile | boolean
$permissions string New filesystem object permissions in numeric (octal, i.e. '0755') format
$recursive boolean Apply permissions to directory contents flag.
Результат CFile | boolean Current CFile object on success, 'False' on fail.