‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Http\UploadedFile Class Reference
Inheritance diagram for TYPO3\CMS\Core\Http\UploadedFile:

Public Member Functions

 __construct ($input, int $size, int $errorStatus, ?string $clientFilename=null, ?string $clientMediaType=null)
 
StreamInterface getStream ()
 
 moveTo (string $targetPath)
 
int null getSize ()
 
int getError ()
 
string null getClientFilename ()
 
 getTemporaryFileName ()
 
string null getClientMediaType ()
 

Protected Attributes

string $file = null
 
StreamInterface $stream = null
 
string $clientFilename
 
string $clientMediaType
 
int $error
 
bool $moved = false
 
int $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/

Note that this is not public API yet.

Definition at line 33 of file UploadedFile.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Http\UploadedFile::__construct (   $input,
int  $size,
int  $errorStatus,
?string  $clientFilename = null,
?string  $clientMediaType = null 
)

Constructor method

Parameters
string | resource | StreamInterface$input‪is either a stream or a filename
int$size‪see $_FILES['size'] from PHP
int$errorStatus‪see $_FILES['error']
string | null$clientFilename‪the original filename handed over from the client
string | null$clientMediaType‪the media type (optional)
Exceptions

Definition at line 54 of file UploadedFile.php.

References TYPO3\CMS\Core\Http\UploadedFile\$clientFilename, TYPO3\CMS\Core\Http\UploadedFile\$clientMediaType, and TYPO3\CMS\Core\Http\UploadedFile\$size.

Member Function Documentation

◆ getClientFilename()

string null TYPO3\CMS\Core\Http\UploadedFile::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.

Definition at line 227 of file UploadedFile.php.

References TYPO3\CMS\Core\Http\UploadedFile\$clientFilename.

Referenced by TYPO3\CMS\Core\Resource\ResourceStorage\addUploadedFile(), and TYPO3\CMS\Form\Mvc\Property\TypeConverter\UploadedFileReferenceConverter\convertUploadedFileToUploadInfoArray().

◆ getClientMediaType()

string null TYPO3\CMS\Core\Http\UploadedFile::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.

Definition at line 257 of file UploadedFile.php.

References TYPO3\CMS\Core\Http\UploadedFile\$clientMediaType.

Referenced by TYPO3\CMS\Form\Mvc\Property\TypeConverter\UploadedFileReferenceConverter\convertUploadedFileToUploadInfoArray().

◆ getError()

int TYPO3\CMS\Core\Http\UploadedFile::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
https://php.net/manual/en/features.file-upload.errors.php
Returns
‪int One of PHP's UPLOAD_ERR_XXX constants.

Definition at line 211 of file UploadedFile.php.

References TYPO3\CMS\Core\Http\UploadedFile\$error.

Referenced by TYPO3\CMS\Form\Mvc\Property\TypeConverter\UploadedFileReferenceConverter\convertUploadedFileToUploadInfoArray().

◆ getSize()

int null TYPO3\CMS\Core\Http\UploadedFile::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.

Definition at line 193 of file UploadedFile.php.

References TYPO3\CMS\Core\Http\UploadedFile\$size.

Referenced by TYPO3\CMS\Core\Resource\ResourceStorage\addUploadedFile(), and TYPO3\CMS\Form\Mvc\Property\TypeConverter\UploadedFileReferenceConverter\convertUploadedFileToUploadInfoArray().

◆ getStream()

StreamInterface TYPO3\CMS\Core\Http\UploadedFile::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

Definition at line 96 of file UploadedFile.php.

References TYPO3\CMS\Core\Http\UploadedFile\$stream.

◆ getTemporaryFileName()

TYPO3\CMS\Core\Http\UploadedFile::getTemporaryFileName ( )

Retrieve the temporary file name (for example /tmp/tmp_foo_filexyz If the file has been moved (by moveTo) an exception is thrown.

Not part of the PSR interface - used for legacy code in the core

Definition at line 238 of file UploadedFile.php.

References TYPO3\CMS\Core\Http\UploadedFile\$file.

Referenced by TYPO3\CMS\Core\Resource\ResourceStorage\addUploadedFile(), and TYPO3\CMS\Form\Mvc\Property\TypeConverter\UploadedFileReferenceConverter\convertUploadedFileToUploadInfoArray().

◆ moveTo()

TYPO3\CMS\Core\Http\UploadedFile::moveTo ( string  $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
https://php.net/is_uploaded_file
https://php.net/move_uploaded_file
Parameters
string$targetPath‪Path to which to move the uploaded file.
Exceptions

Definition at line 141 of file UploadedFile.php.

Member Data Documentation

◆ $clientFilename

string TYPO3\CMS\Core\Http\UploadedFile::$clientFilename
protected

◆ $clientMediaType

string TYPO3\CMS\Core\Http\UploadedFile::$clientMediaType
protected

◆ $error

int TYPO3\CMS\Core\Http\UploadedFile::$error
protected

Definition at line 39 of file UploadedFile.php.

Referenced by TYPO3\CMS\Core\Http\UploadedFile\getError().

◆ $file

string TYPO3\CMS\Core\Http\UploadedFile::$file = null
protected

◆ $moved

bool TYPO3\CMS\Core\Http\UploadedFile::$moved = false
protected

Definition at line 40 of file UploadedFile.php.

◆ $size

int TYPO3\CMS\Core\Http\UploadedFile::$size
protected

◆ $stream

StreamInterface TYPO3\CMS\Core\Http\UploadedFile::$stream = null
protected

Definition at line 36 of file UploadedFile.php.

Referenced by TYPO3\CMS\Core\Http\UploadedFile\getStream().