Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
GuzzleHttp\Psr7\UploadedFile Class Reference
Inheritance diagram for GuzzleHttp\Psr7\UploadedFile:
Psr\Http\Message\UploadedFileInterface

Public Member Functions

 __construct ( $streamOrFile, ?int $size, int $errorStatus, string $clientFilename=null, string $clientMediaType=null)
 
 getClientFilename ()
 Retrieve the filename sent by the client.
 
 getClientMediaType ()
 Retrieve the media type sent by the client.
 
 getError ()
 Retrieve the error associated with the uploaded file.
 
 getSize ()
 Retrieve the file size.
 
 getStream ()
 Retrieve a stream representing the uploaded file.
 
 isMoved ()
 
 moveTo ($targetPath)
 Move the uploaded file to a new location.
 

Constructor & Destructor Documentation

◆ __construct()

GuzzleHttp\Psr7\UploadedFile::__construct ( $streamOrFile,
?int $size,
int $errorStatus,
string $clientFilename = null,
string $clientMediaType = null )
Parameters
StreamInterface | string | resource$streamOrFile

Member Function Documentation

◆ getClientFilename()

GuzzleHttp\Psr7\UploadedFile::getClientFilename ( )

Retrieve the filename sent by the client.

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.

Implementations SHOULD return the value stored in the "name" key of the file in the $_FILES array.

Return values
string|nullThe filename sent by the client or null if none was provided.

Implements Psr\Http\Message\UploadedFileInterface.

◆ getClientMediaType()

GuzzleHttp\Psr7\UploadedFile::getClientMediaType ( )

Retrieve the media type sent by the client.

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.

Implementations SHOULD return the value stored in the "type" key of the file in the $_FILES array.

Return values
string|nullThe media type sent by the client or null if none was provided.

Implements Psr\Http\Message\UploadedFileInterface.

◆ getError()

GuzzleHttp\Psr7\UploadedFile::getError ( )

Retrieve the error associated with the uploaded file.

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.

Implementations SHOULD return the value stored in the "error" key of the file in the $_FILES array.

See also
http://php.net/manual/en/features.file-upload.errors.php
Return values
intOne of PHP's UPLOAD_ERR_XXX constants.

Implements Psr\Http\Message\UploadedFileInterface.

◆ getSize()

GuzzleHttp\Psr7\UploadedFile::getSize ( )

Retrieve the file size.

Implementations SHOULD return 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.

Return values
int|nullThe file size in bytes or null if unknown.

Implements Psr\Http\Message\UploadedFileInterface.

◆ getStream()

GuzzleHttp\Psr7\UploadedFile::getStream ( )

Retrieve a stream representing the uploaded file.

This method MUST return 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 MUST raise an exception.

Return values
StreamInterfaceStream representation of the uploaded file.
Exceptions
RuntimeExceptionin cases when no stream is available or can be created.

Implements Psr\Http\Message\UploadedFileInterface.

◆ moveTo()

GuzzleHttp\Psr7\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
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 $targetPath specified is invalid.
RuntimeExceptionon any error during the move operation, or on the second or subsequent call to the method.

Implements Psr\Http\Message\UploadedFileInterface.


The documentation for this class was generated from the following file: