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

Public Member Functions

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

Protected Attributes

string null $file
 
StreamInterface null $stream
 
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 30 of file UploadedFile.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Http\UploadedFile::__construct (   $input,
  $size,
  $errorStatus,
  $clientFilename = null,
  $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$clientFilename‪the original filename handed over from the client
string$clientMediaType‪the media type (optional)
Exceptions

Definition at line 71 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 244 of file UploadedFile.php.

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

◆ 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 260 of file UploadedFile.php.

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

◆ 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 228 of file UploadedFile.php.

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

◆ 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 210 of file UploadedFile.php.

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

◆ 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 120 of file UploadedFile.php.

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

◆ moveTo()

TYPO3\CMS\Core\Http\UploadedFile::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
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 165 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 50 of file UploadedFile.php.

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

◆ $file

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

Definition at line 34 of file UploadedFile.php.

◆ $moved

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

Definition at line 54 of file UploadedFile.php.

◆ $size

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

◆ $stream

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

Definition at line 38 of file UploadedFile.php.

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