PHP Class FileUpload\FileUpload

ファイルを表示 Open project: gargron/fileupload Class Usage Examples

Protected Properties

Property Type Description
$callbacks array Callbacks to be run
$fileContainer FileUpload\File File Container instance
$filename_generator FileUpload\FileNameGenerator\FileNameGenerator Path resolver instance
$files array The array of uploaded files
$filesystem FileUpload\FileSystem\FileSystem File system instance
$logger Psr\Log\LoggerInterface Optional logger
$messages array Default messages
$pathresolver FileUpload\PathResolver\PathResolver Path resolver instance
$server array $_SERVER
$upload array $_FILES
$validators array Validators to be run

Public Methods

Method Description
__construct ( array $upload, array $server, FileUpload\FileNameGenerator\FileNameGenerator $generator = null ) Construct this mother
addCallback ( string $event, Closure $callback ) Register callback for an event
addValidator ( FileUpload\Validator\Validator $v ) Add another validator
getFileContainer ( ) : FileUpload\File
getFileNameGenerator ( ) : FileUpload\FileNameGenerator\FileNameGenerator
getFileSystem ( ) : FileUpload\FileSystem\FileSystem
getFiles ( ) : array Returns an array of all uploaded files
getLogger ( ) : Psr\Log\LoggerInterface
getMessage ( integer $code ) : string Get an error message
getPathResolver ( ) : FileUpload\PathResolver\PathResolver
processAll ( ) : array Process entire submitted request
setFileNameGenerator ( FileUpload\FileNameGenerator\FileNameGenerator $fng ) Set filename generator
setFileSystem ( FileUpload\FileSystem\FileSystem $fs ) Set file system
setLogger ( Psr\Log\LoggerInterface $logger ) Set logger, optionally
setMessages ( array $new_messages ) Merge (overwrite) default error messages
setPathResolver ( FileUpload\PathResolver\PathResolver $pr ) Set path resolver

Protected Methods

Method Description
fixIntegerOverflow ( integer $int ) : float Ensure correct value for big integers
getConfigBytes ( string $val ) : float Convert size format from PHP config into bytes
getContentLength ( ) : integer Content-length header
getContentRange ( ) : array Content-range header
getContentType ( ) : string Content-type header
getFilename ( string $name, string $type, integer $index, array $content_range, string $tmp_name ) : string Get filename for submitted filename
getFilesize ( string $path, boolean $clear_cache = false ) : float Get size of file
getNewHeaders ( array $files, array $content_range ) : array Generate headers for response
getSize ( ) : integer Request size
process ( string $tmp_name, string $name, integer $size, string $type, integer $error, integer $index, array $content_range = null ) : FileUpload\File Process single submitted file
processCallbacksFor ( string $eventName, FileUpload\File $file ) : void Process callbacks for a given event
trimFilename ( string $name, string $type, integer $index, array $content_range ) : string Remove harmful characters from filename
validate ( string $tmp_name, FileUpload\File $file, integer $error, integer $index ) : boolean Validate upload using some default rules, and custom validators added via addValidator. Default rules:

Private Methods

Method Description
prepareMessages ( ) Converts $messages array into a hash with strings as keys This allows us to work with the keys and values as if it was a hash Which it really should be but, well, arrays in PHP, am I right?

Method Details

__construct() public method

Construct this mother
public __construct ( array $upload, array $server, FileUpload\FileNameGenerator\FileNameGenerator $generator = null )
$upload array
$server array
$generator FileUpload\FileNameGenerator\FileNameGenerator

addCallback() public method

Register callback for an event
public addCallback ( string $event, Closure $callback )
$event string
$callback Closure

addValidator() public method

Add another validator
public addValidator ( FileUpload\Validator\Validator $v )
$v FileUpload\Validator\Validator

fixIntegerOverflow() protected method

Ensure correct value for big integers
protected fixIntegerOverflow ( integer $int ) : float
$int integer
return float

getConfigBytes() protected method

Convert size format from PHP config into bytes
protected getConfigBytes ( string $val ) : float
$val string
return float

getContentLength() protected method

Content-length header
protected getContentLength ( ) : integer
return integer

getContentRange() protected method

Content-range header
protected getContentRange ( ) : array
return array

getContentType() protected method

Content-type header
protected getContentType ( ) : string
return string

getFileContainer() public method

public getFileContainer ( ) : FileUpload\File
return FileUpload\File

getFileNameGenerator() public method

public getFileNameGenerator ( ) : FileUpload\FileNameGenerator\FileNameGenerator
return FileUpload\FileNameGenerator\FileNameGenerator

getFileSystem() public method

public getFileSystem ( ) : FileUpload\FileSystem\FileSystem
return FileUpload\FileSystem\FileSystem

getFilename() protected method

Get filename for submitted filename
protected getFilename ( string $name, string $type, integer $index, array $content_range, string $tmp_name ) : string
$name string
$type string
$index integer
$content_range array
$tmp_name string
return string

getFiles() public method

Returns an array of all uploaded files
public getFiles ( ) : array
return array

getFilesize() protected method

Get size of file
protected getFilesize ( string $path, boolean $clear_cache = false ) : float
$path string
$clear_cache boolean
return float

getLogger() public method

public getLogger ( ) : Psr\Log\LoggerInterface
return Psr\Log\LoggerInterface

getMessage() public method

Get an error message
public getMessage ( integer $code ) : string
$code integer
return string

getNewHeaders() protected method

Generate headers for response
protected getNewHeaders ( array $files, array $content_range ) : array
$files array
$content_range array
return array

getPathResolver() public method

public getPathResolver ( ) : FileUpload\PathResolver\PathResolver
return FileUpload\PathResolver\PathResolver

getSize() protected method

Request size
protected getSize ( ) : integer
return integer

process() protected method

Process single submitted file
protected process ( string $tmp_name, string $name, integer $size, string $type, integer $error, integer $index, array $content_range = null ) : FileUpload\File
$tmp_name string
$name string
$size integer
$type string
$error integer
$index integer
$content_range array
return FileUpload\File

processAll() public method

Process entire submitted request
public processAll ( ) : array
return array Files and response headers

processCallbacksFor() protected method

Process callbacks for a given event
protected processCallbacksFor ( string $eventName, FileUpload\File $file ) : void
$eventName string
$file FileUpload\File
return void

setFileNameGenerator() public method

Set filename generator
public setFileNameGenerator ( FileUpload\FileNameGenerator\FileNameGenerator $fng )
$fng FileUpload\FileNameGenerator\FileNameGenerator

setFileSystem() public method

Set file system
public setFileSystem ( FileUpload\FileSystem\FileSystem $fs )
$fs FileUpload\FileSystem\FileSystem

setLogger() public method

Set logger, optionally
public setLogger ( Psr\Log\LoggerInterface $logger )
$logger Psr\Log\LoggerInterface

setMessages() public method

Merge (overwrite) default error messages
public setMessages ( array $new_messages )
$new_messages array

setPathResolver() public method

Set path resolver
public setPathResolver ( FileUpload\PathResolver\PathResolver $pr )
$pr FileUpload\PathResolver\PathResolver

trimFilename() protected method

Remove harmful characters from filename
protected trimFilename ( string $name, string $type, integer $index, array $content_range ) : string
$name string
$type string
$index integer
$content_range array
return string

validate() protected method

- No PHP errors from $_FILES - File size permitted by PHP config
protected validate ( string $tmp_name, FileUpload\File $file, integer $error, integer $index ) : boolean
$tmp_name string
$file FileUpload\File
$error integer
$index integer
return boolean

Property Details

$callbacks protected_oe property

Callbacks to be run
protected array $callbacks
return array

$fileContainer protected_oe property

File Container instance
protected File,FileUpload $fileContainer
return FileUpload\File

$filename_generator protected_oe property

Path resolver instance
protected FileNameGenerator,FileUpload\FileNameGenerator $filename_generator
return FileUpload\FileNameGenerator\FileNameGenerator

$files protected_oe property

The array of uploaded files
protected array $files
return array

$filesystem protected_oe property

File system instance
protected FileSystem,FileUpload\FileSystem $filesystem
return FileUpload\FileSystem\FileSystem

$logger protected_oe property

Optional logger
protected LoggerInterface,Psr\Log $logger
return Psr\Log\LoggerInterface

$messages protected_oe property

Default messages
protected array $messages
return array

$pathresolver protected_oe property

Path resolver instance
protected PathResolver,FileUpload\PathResolver $pathresolver
return FileUpload\PathResolver\PathResolver

$server protected_oe property

$_SERVER
protected array $server
return array

$upload protected_oe property

$_FILES
protected array $upload
return array

$validators protected_oe property

Validators to be run
protected array $validators
return array