UploadedFile
API reference › PSR bridge › http › UploadedFile
Extends Yii uploaded file handling with PSR-7 uploaded files.
Successful upload conversion detaches the PSR stream resource for Yii file handling. Failed uploads preserve
their error without accessing the stream. reset() closes retained resources and clears both bridge and
parent Yii caches; the bridge application invokes it before attaching each request.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$_files static | array<string, | Uploaded files cache. Default: []. | UploadedFile |
$baseName read-only | string | Original file base name. | yii\ |
$error | int | An error code describing the status of this file uploading. Default: null. | yii\ |
$extension read-only | string | File extension. | yii\ |
$fullPath | string| | The full path as submitted by the browser. Default: null. Available since 2.0.46. | yii\ |
$hasError read-only | bool | Whether there is an error with the uploaded file. | yii\ |
$name | string | The original name of the file being uploaded Default: null. | yii\ |
$size | int | The actual size of the uploaded file in bytes Default: null. | yii\ |
$tempName | string | The path of the uploaded file on the server. Default: null. | yii\ |
$type | string | The MIME-type of the uploaded file (such as “image/gif”). Default: null. | yii\ |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | UploadedFile constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__get() | Returns the value of an object property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets value of an object property. | yii\ |
__toString() | String output. | yii\ |
__unset() | Sets an object property to null. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
getBaseName() | yii\ | |
getExtension() | yii\ | |
getHasError() | yii\ | |
getInstance() static | Returns the instance of the uploaded file associated with the specified model attribute. | UploadedFile |
getInstanceByName() static | Returns the instance of the uploaded file for the specified input name. | UploadedFile |
getInstances() static | Returns an array of uploaded file instances associated with the specified model attribute. | UploadedFile |
getInstancesByName() static | Returns an array of uploaded file instances for the specified input name. | UploadedFile |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined. | yii\ |
init() | Initializes the object. | yii\ |
reset() static | Resets the internal uploaded files cache, PSR-7 adapter state, and closes any open tempResource handles. | UploadedFile |
saveAs() | Saves the uploaded file. | yii\ |
setPsr7Adapter() static | Sets the PSR-7 ServerRequestAdapter for file handling. | UploadedFile |
copyTempFile() protected | Copy temporary file into file specified | yii\ |
Method details
Section titled “Method details”getInstance()
Section titled “getInstance() ”public static function getInstance(yii\base\Model $model, string $attribute): yii2\extensions\psrbridge\http\UploadedFile|nullReturns the instance of the uploaded file associated with the specified model attribute.
Retrieves the uploaded file instance for the given model and attribute, supporting array-indexed attribute names
such as ‘[1]file’ for tabular uploads or ‘file[1]’ for file arrays. The method resolves the input name using
Html::getInputName() and delegates to getInstanceByName() for file lookup.
Parameters
| Parameter | Type | Description |
|---|---|---|
$model | yii\ | Data model. |
$attribute | string | Attribute name, which may contain array indexes (for example, ‘[1]file’, ‘file[1]’). |
Returns
UploadedFile|null: Instance of the uploaded file, or null if no file was uploaded for the attribute.
getInstanceByName()
Section titled “getInstanceByName() ”public static function getInstanceByName(string $name): self|nullReturns the instance of the uploaded file for the specified input name.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Name of the file input field. |
Returns
self|null: Instance of the uploaded file, or null if no file was uploaded for the name.
getInstances()
Section titled “getInstances() ”public static function getInstances(yii\base\Model $model, string $attribute): list<yii2\extensions\psrbridge\http\UploadedFile>Returns an array of uploaded file instances associated with the specified model attribute.
Resolves the input name for the given model and attribute using Html::getInputName() and delegates to
getInstancesByName() for file lookup. Supports array-indexed attribute names for tabular file uploading,
such as ‘[1]file’.
Parameters
| Parameter | Type | Description |
|---|---|---|
$model | yii\ | Data model. |
$attribute | string | Attribute name, which may contain array indexes (for example, ‘[1]file’). |
Returns
list<UploadedFile>: Uploaded files for the attribute.
getInstancesByName()
Section titled “getInstancesByName() ”public static function getInstancesByName(string $name): list<yii2\extensions\psrbridge\http\UploadedFile>Returns an array of uploaded file instances for the specified input name.
Iterates over the internal file cache and collects all uploaded files whose keys match the given input name or are prefixed with the input name followed by an opening bracket (for array-style file inputs).
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Name of the file input field or array of files. |
Returns
list<UploadedFile>: Uploaded files for the input name.
reset()
Section titled “reset() ”public static function reset(): voidResets the internal uploaded files cache, PSR-7 adapter state, and closes any open tempResource handles.
setPsr7Adapter()
Section titled “setPsr7Adapter() ”public static function setPsr7Adapter(yii2\extensions\psrbridge\adapter\ServerRequestAdapter $adapter): voidSets the PSR-7 ServerRequestAdapter for file handling.
Parameters
| Parameter | Type | Description |
|---|---|---|
$adapter | yii2\ | PSR-7 adapter containing UploadedFileInterface instances. |