Skip to content
PHP Ecosystem
Explore

UploadedFile

API reference › PSR bridge › http › UploadedFile

classyii2\extensions\psrbridge\http\UploadedFile
Extendsyii\web\UploadedFile » yii\base\BaseObject
Implementsyii\base\Configurable
Sourcesrc/http/UploadedFile.php

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.

PropertyTypeDescriptionDefined by
$_files staticarray<string, array{name: string, tempName: string, tempResource: resource|null, type: string, size: int, error: int, fullPath: string|null}>Uploaded files cache. Default: [].UploadedFile
$baseName read-onlystringOriginal file base name.yii\web\UploadedFile
$errorintAn error code describing the status of this file uploading. Default: null.yii\web\UploadedFile
$extension read-onlystringFile extension.yii\web\UploadedFile
$fullPathstring|nullThe full path as submitted by the browser. Default: null. Available since 2.0.46.yii\web\UploadedFile
$hasError read-onlyboolWhether there is an error with the uploaded file.yii\web\UploadedFile
$namestringThe original name of the file being uploaded Default: null.yii\web\UploadedFile
$sizeintThe actual size of the uploaded file in bytes Default: null.yii\web\UploadedFile
$tempNamestringThe path of the uploaded file on the server. Default: null.yii\web\UploadedFile
$typestringThe MIME-type of the uploaded file (such as “image/gif”). Default: null.yii\web\UploadedFile
MethodDescriptionDefined by
__construct()UploadedFile constructor.yii\web\UploadedFile
__call()Calls the named method which is not a class method.yii\base\BaseObject
__get()Returns the value of an object property.yii\base\BaseObject
__isset()Checks if a property is set, i.e. defined and not null.yii\base\BaseObject
__set()Sets value of an object property.yii\base\BaseObject
__toString()String output.yii\web\UploadedFile
__unset()Sets an object property to null.yii\base\BaseObject
canGetProperty()Returns a value indicating whether a property can be read.yii\base\BaseObject
canSetProperty()Returns a value indicating whether a property can be set.yii\base\BaseObject
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
getBaseName()yii\web\UploadedFile
getExtension()yii\web\UploadedFile
getHasError()yii\web\UploadedFile
getInstance() staticReturns the instance of the uploaded file associated with the specified model attribute.UploadedFile
getInstanceByName() staticReturns the instance of the uploaded file for the specified input name.UploadedFile
getInstances() staticReturns an array of uploaded file instances associated with the specified model attribute.UploadedFile
getInstancesByName() staticReturns an array of uploaded file instances for the specified input name.UploadedFile
hasMethod()Returns a value indicating whether a method is defined.yii\base\BaseObject
hasProperty()Returns a value indicating whether a property is defined.yii\base\BaseObject
init()Initializes the object.yii\base\BaseObject
reset() staticResets the internal uploaded files cache, PSR-7 adapter state, and closes any open tempResource handles.UploadedFile
saveAs()Saves the uploaded file.yii\web\UploadedFile
setPsr7Adapter() staticSets the PSR-7 ServerRequestAdapter for file handling.UploadedFile
copyTempFile() protectedCopy temporary file into file specifiedyii\web\UploadedFile
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() and delegates to getInstanceByName() for file lookup.

Parameters

ParameterTypeDescription
$modelyii\base\ModelData model.
$attributestringAttribute 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.

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

Returns the instance of the uploaded file for the specified input name.

Parameters

ParameterTypeDescription
$namestringName of the file input field.

Returns

self|null: Instance of the uploaded file, or null if no file was uploaded for the name.

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

ParameterTypeDescription
$modelyii\base\ModelData model.
$attributestringAttribute name, which may contain array indexes (for example, ‘[1]file’).

Returns

list<UploadedFile>: Uploaded files for the attribute.

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

ParameterTypeDescription
$namestringName of the file input field or array of files.

Returns

list<UploadedFile>: Uploaded files for the input name.

public static function reset(): void

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

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

Sets the PSR-7 ServerRequestAdapter for file handling.

Parameters

ParameterTypeDescription
$adapteryii2\extensions\psrbridge\adapter\ServerRequestAdapterPSR-7 adapter containing UploadedFileInterface instances.