# UploadedFileCreator

> Creates PSR-7 uploaded files from PHP file specifications.

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

| final class | `yii2\extensions\psrbridge\creator\UploadedFileCreator` |
| --- | --- |
| Source | [`src/creator/UploadedFileCreator.php`](https://github.com/yii2-extensions/psr-bridge/blob/main/src/creator/UploadedFileCreator.php#L39) |

Creates PSR-7 uploaded files from PHP file specifications.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a new instance of the [`UploadedFileCreator`](/docs/extensions/psr-bridge/reference/creator/uploadedfilecreator/index.md) class. | `UploadedFileCreator` |
| [`createFromArray()`](#method-createFromArray) | Creates an UploadedFileInterface instance from a file specification array. | `UploadedFileCreator` |
| [`createFromGlobals()`](#method-createFromGlobals) | Creates UploadedFileInterface instances from PHP global files array. | `UploadedFileCreator` |

## Method details

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

```php
public function __construct(Psr\Http\Message\UploadedFileFactoryInterface $uploadedFileFactory, Psr\Http\Message\StreamFactoryInterface $streamFactory)
```

Creates a new instance of the [`UploadedFileCreator`](/docs/extensions/psr-bridge/reference/creator/uploadedfilecreator/index.md) class.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$uploadedFileFactory` | `Psr\Http\Message\UploadedFileFactoryInterface` | Factory to create uploaded files. |
| `$streamFactory` | `Psr\Http\Message\StreamFactoryInterface` | Factory to create streams. |

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

```php
public function createFromArray(yii2\extensions\psrbridge\creator\FileSpec $file): Psr\Http\Message\UploadedFileInterface
```

Creates an UploadedFileInterface instance from a file specification array.

Validates the input file specification and delegates stream and uploaded file creation to the configured PSR-7
factories.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$file` | `yii2\extensions\psrbridge\creator\FileSpec` | File specification with required upload fields and optional name and type. |

**Returns**

`Psr\Http\Message\UploadedFileInterface`: Created uploaded file; failed uploads receive an empty stream.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): when the specification is invalid or a successful upload cannot be opened.

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

```php
public function createFromGlobals(yii2\extensions\psrbridge\creator\FilesArray $files = []): yii2\extensions\psrbridge\creator\FilesArray
```

Creates UploadedFileInterface instances from PHP global files array.

Iterates over the provided files array and processes each entry using `processFileInput`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$files` | `yii2\extensions\psrbridge\creator\FilesArray` | Uploaded file specifications or PSR-7 uploaded files. |

**Returns**

`yii2\extensions\psrbridge\creator\FilesArray`: Processed uploaded files, preserving nested file trees.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): when specifications are invalid, nesting exceeds 10, or a successful upload cannot be opened.