# UploadedFile

> Extends Yii uploaded file handling with PSR-7 uploaded files.

[API reference](/docs/api/index.md) › [PSR bridge](/docs/extensions/psr-bridge/reference/index.md) › [http](/docs/extensions/psr-bridge/reference/http/index.md) › UploadedFile

| class | `yii2\extensions\psrbridge\http\UploadedFile` |
| --- | --- |
| Extends | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Source | [`src/http/UploadedFile.php`](https://github.com/yii2-extensions/psr-bridge/blob/main/src/http/UploadedFile.php#L27) |

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()`](/docs/extensions/psr-bridge/reference/http/uploadedfile/index.md#method-reset) closes retained resources and clears both bridge and
parent Yii caches; the bridge application invokes it before attaching each request.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-_files"></span>`$_files` static | `array<string, array{name: string, tempName: string, tempResource: resource\|null, type: string, size: int, error: int, fullPath: string\|null}>` | Uploaded files cache. Default: `[]`. | `UploadedFile` |
| <span id="property-baseName"></span>[`$baseName`](/docs/api/yii/web/uploadedfile/index.md#property-baseName) read-only | `string` | Original file base name. | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) |
| <span id="property-error"></span>[`$error`](/docs/api/yii/web/uploadedfile/index.md#property-error) | `int` | An error code describing the status of this file uploading. Default: `null`. | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) |
| <span id="property-extension"></span>[`$extension`](/docs/api/yii/web/uploadedfile/index.md#property-extension) read-only | `string` | File extension. | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) |
| <span id="property-fullPath"></span>[`$fullPath`](/docs/api/yii/web/uploadedfile/index.md#property-fullPath) | `string\|null` | The full path as submitted by the browser. Default: `null`. Available since 2.0.46. | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) |
| <span id="property-hasError"></span>[`$hasError`](/docs/api/yii/web/uploadedfile/index.md#property-hasError) read-only | `bool` | Whether there is an error with the uploaded file. | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) |
| <span id="property-name"></span>[`$name`](/docs/api/yii/web/uploadedfile/index.md#property-name) | `string` | The original name of the file being uploaded Default: `null`. | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) |
| <span id="property-size"></span>[`$size`](/docs/api/yii/web/uploadedfile/index.md#property-size) | `int` | The actual size of the uploaded file in bytes Default: `null`. | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) |
| <span id="property-tempName"></span>[`$tempName`](/docs/api/yii/web/uploadedfile/index.md#property-tempName) | `string` | The path of the uploaded file on the server. Default: `null`. | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) |
| <span id="property-type"></span>[`$type`](/docs/api/yii/web/uploadedfile/index.md#property-type) | `string` | The MIME-type of the uploaded file (such as "image/gif"). Default: `null`. | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/web/uploadedfile/index.md#method-__construct) | UploadedFile constructor. | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/baseobject/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/baseobject/index.md#method-__get) | Returns the value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/baseobject/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/baseobject/index.md#method-__set) | Sets value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__toString"></span>[`__toString()`](/docs/api/yii/web/uploadedfile/index.md#method-__toString) | String output. | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/baseobject/index.md#method-__unset) | Sets an object property to null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-getBaseName"></span>[`getBaseName()`](/docs/api/yii/web/uploadedfile/index.md#method-getBaseName) |  | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) |
| <span id="method-getExtension"></span>[`getExtension()`](/docs/api/yii/web/uploadedfile/index.md#method-getExtension) |  | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) |
| <span id="method-getHasError"></span>[`getHasError()`](/docs/api/yii/web/uploadedfile/index.md#method-getHasError) |  | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) |
| [`getInstance()`](#method-getInstance) static | Returns the instance of the uploaded file associated with the specified model attribute. | `UploadedFile` |
| [`getInstanceByName()`](#method-getInstanceByName) static | Returns the instance of the uploaded file for the specified input name. | `UploadedFile` |
| [`getInstances()`](#method-getInstances) static | Returns an array of uploaded file instances associated with the specified model attribute. | `UploadedFile` |
| [`getInstancesByName()`](#method-getInstancesByName) static | Returns an array of uploaded file instances for the specified input name. | `UploadedFile` |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/baseobject/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/baseobject/index.md#method-hasProperty) | Returns a value indicating whether a property is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/baseobject/index.md#method-init) | Initializes the object. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`reset()`](#method-reset) static | Resets the internal uploaded files cache, PSR-7 adapter state, and closes any open tempResource handles. | `UploadedFile` |
| <span id="method-saveAs"></span>[`saveAs()`](/docs/api/yii/web/uploadedfile/index.md#method-saveAs) | Saves the uploaded file. | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) |
| [`setPsr7Adapter()`](#method-setPsr7Adapter) static | Sets the PSR-7 ServerRequestAdapter for file handling. | `UploadedFile` |
| <span id="method-copyTempFile"></span>[`copyTempFile()`](/docs/api/yii/web/uploadedfile/index.md#method-copyTempFile) protected | Copy temporary file into file specified | [`yii\web\UploadedFile`](/docs/api/yii/web/uploadedfile/index.md) |

## Method details

### getInstance() <span id="method-getInstance"></span>

```php
public static function getInstance(yii\base\Model $model, string $attribute): yii2\extensions\psrbridge\http\UploadedFile|null
```

Returns 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()`](/docs/api/yii/helpers/basehtml/index.md#method-getInputName) and delegates to [`getInstanceByName()`](/docs/extensions/psr-bridge/reference/http/uploadedfile/index.md#method-getInstanceByName) for file lookup.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | Data model. |
| `$attribute` | `string` | Attribute name, which may contain array indexes (for example, '[1]file', 'file[1]'). |

**Returns**

[`UploadedFile`](/docs/extensions/psr-bridge/reference/http/uploadedfile/index.md)`|null`: Instance of the uploaded file, or `null` if no file was uploaded for the attribute.

### getInstanceByName() <span id="method-getInstanceByName"></span>

```php
public static function getInstanceByName(string $name): self|null
```

Returns 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() <span id="method-getInstances"></span>

```php
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()`](/docs/api/yii/helpers/basehtml/index.md#method-getInputName) and delegates to
[`getInstancesByName()`](/docs/extensions/psr-bridge/reference/http/uploadedfile/index.md#method-getInstancesByName) for file lookup. Supports array-indexed attribute names for tabular file uploading,
such as '[1]file'.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | Data model. |
| `$attribute` | `string` | Attribute name, which may contain array indexes (for example, '[1]file'). |

**Returns**

`list<`[`UploadedFile`](/docs/extensions/psr-bridge/reference/http/uploadedfile/index.md)`>`: Uploaded files for the attribute.

### getInstancesByName() <span id="method-getInstancesByName"></span>

```php
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`](/docs/extensions/psr-bridge/reference/http/uploadedfile/index.md)`>`: Uploaded files for the input name.

### reset() <span id="method-reset"></span>

```php
public static function reset(): void
```

Resets the internal uploaded files cache, PSR-7 adapter state, and closes any open tempResource handles.

### setPsr7Adapter() <span id="method-setPsr7Adapter"></span>

```php
public static function setPsr7Adapter(yii2\extensions\psrbridge\adapter\ServerRequestAdapter $adapter): void
```

Sets the PSR-7 ServerRequestAdapter for file handling.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$adapter` | [`yii2\extensions\psrbridge\adapter\ServerRequestAdapter`](/docs/extensions/psr-bridge/reference/adapter/serverrequestadapter/index.md) | PSR-7 adapter containing UploadedFileInterface instances. |