TYPO3  7.6
Public Member Functions | Protected Attributes | List of all members
UploadedFile Class Reference
Inheritance diagram for UploadedFile:
UploadedFileInterface

Public Member Functions

 __construct ($input, $size, $errorStatus, $clientFilename=null, $clientMediaType=null)
 
 getStream ()
 
 moveTo ($targetPath)
 
 getSize ()
 
 getError ()
 
 getClientFilename ()
 
 getClientMediaType ()
 

Protected Attributes

 $file
 
 $stream
 
 $clientFilename
 
 $clientMediaType
 
 $error
 
 $moved = false
 
 $size
 

Detailed Description

Class UploadedFile which represents one uploaded file, usually coming from $_FILES, according to PSR-7 standard.

Highly inspired by https://github.com/phly/http/

Definition at line 29 of file UploadedFile.php.

Constructor & Destructor Documentation

__construct (   $input,
  $size,
  $errorStatus,
  $clientFilename = null,
  $clientMediaType = null 
)

Constructor method

Parameters
string | resource$inputis either a stream or a filename
int$sizesee $_FILES['size'] from PHP
int$errorStatussee $_FILES['error']
string$clientFilenamethe original filename handed over from the client
string$clientMediaTypethe media type (optional)
Exceptions
\InvalidArgumentException

Definition at line 77 of file UploadedFile.php.

References UploadedFile\$clientFilename, UploadedFile\$clientMediaType, UploadedFile\$size, and elseif.

Member Function Documentation

getClientFilename ( )

Retrieve the filename sent by the client. Usually returns the value stored in the "name" key of the file in the $_FILES array.

Do not trust the value returned by this method. A client could send a malicious filename with the intention to corrupt or hack your application.

Returns
string|NULL The filename sent by the client or null if none was provided.

Implements UploadedFileInterface.

Definition at line 250 of file UploadedFile.php.

References UploadedFile\$clientFilename.

getClientMediaType ( )

Retrieve the media type sent by the client. Usually returns the value stored in the "type" key of the file in the $_FILES array.

Do not trust the value returned by this method. A client could send a malicious media type with the intention to corrupt or hack your application.

Returns
string|NULL The media type sent by the client or null if none was provided.

Implements UploadedFileInterface.

Definition at line 266 of file UploadedFile.php.

References UploadedFile\$clientMediaType.

getError ( )

Retrieve the error associated with the uploaded file. Usually returns the value stored in the "error" key of the file in the $_FILES array.

The return value MUST be one of PHP's UPLOAD_ERR_XXX constants.

If the file was uploaded successfully, this method MUST return UPLOAD_ERR_OK.

See Also
http://php.net/manual/en/features.file-upload.errors.php
Returns
int One of PHP's UPLOAD_ERR_XXX constants.

Implements UploadedFileInterface.

Definition at line 234 of file UploadedFile.php.

References UploadedFile\$error.

getSize ( )

Retrieve the file size. Usually returns the value stored in the "size" key of the file in the $_FILES array if available, as PHP calculates this based on the actual size transmitted.

Returns
int|NULL The file size in bytes or null if unknown.

Implements UploadedFileInterface.

Definition at line 216 of file UploadedFile.php.

References UploadedFile\$size.

getStream ( )

Retrieve a stream representing the uploaded file. Returns a StreamInterface instance, representing the uploaded file. The purpose of this method is to allow utilizing native PHP stream functionality to manipulate the file upload, such as stream_copy_to_stream() (though the result will need to be decorated in a native PHP stream wrapper to work with such functions).

If the moveTo() method has been called previously, this method raises an exception.

Returns
StreamInterface Stream representation of the uploaded file.
Exceptions
\RuntimeExceptionin cases when no stream is available or can be created.

Implements UploadedFileInterface.

Definition at line 126 of file UploadedFile.php.

References UploadedFile\$stream.

moveTo (   $targetPath)

Move the uploaded file to a new location.

Use this method as an alternative to move_uploaded_file(). This method is guaranteed to work in both SAPI and non-SAPI environments. Implementations must determine which environment they are in, and use the appropriate method (move_uploaded_file(), rename(), or a stream operation) to perform the operation.

$targetPath may be an absolute path, or a relative path. If it is a relative path, resolution should be the same as used by PHP's rename() function.

The original file or stream MUST be removed on completion.

If this method is called more than once, any subsequent calls MUST raise an exception.

When used in an SAPI environment where $_FILES is populated, when writing files via moveTo(), is_uploaded_file() and move_uploaded_file() SHOULD be used to ensure permissions and upload status are verified correctly.

If you wish to move to a stream, use getStream(), as SAPI operations cannot guarantee writing to stream destinations.

See Also
http://php.net/is_uploaded_file
http://php.net/move_uploaded_file
Parameters
string$targetPathPath to which to move the uploaded file.
Exceptions
\InvalidArgumentExceptionif the $path specified is invalid.
\RuntimeExceptionon any error during the move operation, or on the second or subsequent call to the method.

Implements UploadedFileInterface.

Definition at line 171 of file UploadedFile.php.

References elseif, GeneralUtility\getFileAbsFileName(), and GeneralUtility\upload_copy_move().

Member Data Documentation

$clientFilename
protected

Definition at line 44 of file UploadedFile.php.

Referenced by UploadedFile\__construct(), and UploadedFile\getClientFilename().

$clientMediaType
protected

Definition at line 49 of file UploadedFile.php.

Referenced by UploadedFile\__construct(), and UploadedFile\getClientMediaType().

$error
protected

Definition at line 54 of file UploadedFile.php.

Referenced by UploadedFile\getError().

$file
protected

Definition at line 34 of file UploadedFile.php.

$moved = false
protected

Definition at line 59 of file UploadedFile.php.

$size
protected

Definition at line 64 of file UploadedFile.php.

Referenced by UploadedFile\__construct(), and UploadedFile\getSize().

$stream
protected

Definition at line 39 of file UploadedFile.php.

Referenced by UploadedFile\getStream().