PHP Class Pop\File\File

Author: Nick Sagona, III ([email protected])
Show file Open project: nicksagona/PopPHP Class Usage Examples

Protected Properties

Property Type Description
$allowed array Array of allowed file types.
$basename string Full basename of file, i.e. 'file.ext'
$dir string Full, absolute directory of file, i.e. '/some/dir/'
$ext string File extension, i.e. 'ext'
$filename string Full filename of file, i.e. 'file'
$fullpath string Full path and name of the file, i.e. '/some/dir/file.ext'
$mime string File mime type
$output string File output data.
$size integer File size in bytes

Public Methods

Method Description
__construct ( string $file, array $types = null ) : File Constructor
addAllowedTypes ( array $types ) : void Set the allowed files types.
append ( string $data ) : File Append data to a file.
checkDupe ( string $file, string $dir = null ) : string Static method to check for a duplicate file, returning the next incremented filename, i.e. filename_1.txt
copy ( string $new, boolean $overwrite = false ) : File Copy the file object directly to another file on disk.
delete ( ) : void Delete the file object directly from disk.
getAllowedTypes ( ) : array Get the current allowed files types.
getBasename ( ) : string Get the basename.
getDir ( ) : string Get the directory.
getDirGroup ( ) : array Get the owner of the file. Works on POSIX file systems only
getDirOwner ( ) : array Get the owner of the file. Works on POSIX file systems only
getDirPermissions ( ) : string Get the permissions of the directory the file is in.
getExt ( ) : string Get the extension.
getFilename ( ) : string Get the filename.
getFullpath ( ) : string Get the fullpath.
getGroup ( ) : array Get the owner of the file. Works on POSIX file systems only
getMime ( ) : string Get the current file mime type.
getOwner ( ) : array Get the owner of the file. Works on POSIX file systems only
getPermissions ( ) : string Get the permissions of the file.
getSize ( ) : string Get the current file size.
getUser ( ) : array Get current user. Works on POSIX file systems only
isAllowed ( string $type ) : boolean Test if a certain file type is allowed.
isDir ( ) : boolean Is dir object.
isFile ( ) : boolean Is file object.
move ( string $new, boolean $overwrite = false ) : File Move the file object directly to another location on disk.
output ( boolean $download = false ) : File Output the file object directly.
read ( integer | string $off = null, integer | string $len = null ) : string Read data from a file.
save ( string $to = null, boolean $append = false ) : File Save the file object to disk.
setAllowedTypes ( array $types = null ) : void Set the allowed files types, overriding any previously allowed types.
setDirPermissions ( mixed $mode ) : File Change the permissions of the directory the file is in.
setMime ( string $mime ) : File Set the file mime type.
setPermissions ( mixed $mode ) : File Change the permissions of the file.
upload ( string $upload, string $file, integer $size, array $types = null ) : File Static method to upload a file and return a file object.
write ( string $data, boolean $append = false ) : File Write data to a file.

Protected Methods

Method Description
setFile ( string $file, array $types = null ) : void Set the file and its properties.

Method Details

__construct() public method

Instantiate the file object, either from a file on disk or as a new file.
public __construct ( string $file, array $types = null ) : File
$file string
$types array
return File

addAllowedTypes() public method

Set the allowed files types.
public addAllowedTypes ( array $types ) : void
$types array
return void

append() public method

Append data to a file.
public append ( string $data ) : File
$data string
return File

checkDupe() public static method

Static method to check for a duplicate file, returning the next incremented filename, i.e. filename_1.txt
public static checkDupe ( string $file, string $dir = null ) : string
$file string
$dir string
return string

copy() public method

Copy the file object directly to another file on disk.
public copy ( string $new, boolean $overwrite = false ) : File
$new string
$overwrite boolean
return File

delete() public method

Delete the file object directly from disk.
public delete ( ) : void
return void

getAllowedTypes() public method

Get the current allowed files types.
public getAllowedTypes ( ) : array
return array

getBasename() public method

Get the basename.
public getBasename ( ) : string
return string

getDir() public method

Get the directory.
public getDir ( ) : string
return string

getDirGroup() public method

Get the owner of the file. Works on POSIX file systems only
public getDirGroup ( ) : array
return array

getDirOwner() public method

Get the owner of the file. Works on POSIX file systems only
public getDirOwner ( ) : array
return array

getDirPermissions() public method

Get the permissions of the directory the file is in.
public getDirPermissions ( ) : string
return string

getExt() public method

Get the extension.
public getExt ( ) : string
return string

getFilename() public method

Get the filename.
public getFilename ( ) : string
return string

getFullpath() public method

Get the fullpath.
public getFullpath ( ) : string
return string

getGroup() public method

Get the owner of the file. Works on POSIX file systems only
public getGroup ( ) : array
return array

getMime() public method

Get the current file mime type.
public getMime ( ) : string
return string

getOwner() public method

Get the owner of the file. Works on POSIX file systems only
public getOwner ( ) : array
return array

getPermissions() public method

Get the permissions of the file.
public getPermissions ( ) : string
return string

getSize() public method

Get the current file size.
public getSize ( ) : string
return string

getUser() public method

Get current user. Works on POSIX file systems only
public getUser ( ) : array
return array

isAllowed() public method

Test if a certain file type is allowed.
public isAllowed ( string $type ) : boolean
$type string
return boolean

isDir() public method

Is dir object.
public isDir ( ) : boolean
return boolean

isFile() public method

Is file object.
public isFile ( ) : boolean
return boolean

move() public method

Move the file object directly to another location on disk.
public move ( string $new, boolean $overwrite = false ) : File
$new string
$overwrite boolean
return File

output() public method

Output the file object directly.
public output ( boolean $download = false ) : File
$download boolean
return File

read() public method

Read data from a file.
public read ( integer | string $off = null, integer | string $len = null ) : string
$off integer | string
$len integer | string
return string

save() public method

Save the file object to disk.
public save ( string $to = null, boolean $append = false ) : File
$to string
$append boolean
return File

setAllowedTypes() public method

Set the allowed files types, overriding any previously allowed types.
public setAllowedTypes ( array $types = null ) : void
$types array
return void

setDirPermissions() public method

Change the permissions of the directory the file is in.
public setDirPermissions ( mixed $mode ) : File
$mode mixed
return File

setFile() protected method

Set the file and its properties.
protected setFile ( string $file, array $types = null ) : void
$file string
$types array
return void

setMime() public method

Set the file mime type.
public setMime ( string $mime ) : File
$mime string
return File

setPermissions() public method

Change the permissions of the file.
public setPermissions ( mixed $mode ) : File
$mode mixed
return File

upload() public static method

Static method to upload a file and return a file object.
public static upload ( string $upload, string $file, integer $size, array $types = null ) : File
$upload string
$file string
$size integer
$types array
return File

write() public method

Write data to a file.
public write ( string $data, boolean $append = false ) : File
$data string
$append boolean
return File

Property Details

$allowed protected property

Array of allowed file types.
protected array $allowed
return array

$basename protected property

Full basename of file, i.e. 'file.ext'
protected string $basename
return string

$dir protected property

Full, absolute directory of file, i.e. '/some/dir/'
protected string $dir
return string

$ext protected property

File extension, i.e. 'ext'
protected string $ext
return string

$filename protected property

Full filename of file, i.e. 'file'
protected string $filename
return string

$fullpath protected property

Full path and name of the file, i.e. '/some/dir/file.ext'
protected string $fullpath
return string

$mime protected property

File mime type
protected string $mime
return string

$output protected property

File output data.
protected string $output
return string

$size protected property

File size in bytes
protected int $size
return integer