PHP 클래스 CFile

파일 보기 프로젝트 열기: idlesign/ist-yii-cfile 1 사용 예제들

공개 메소드들

메소드 설명
__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.