Craft 3 Class Reference

Class craft\web\UploadedFile

Inheritance
craft\web\UploadedFile » yii\web\UploadedFile » yii\base\BaseObject
Implements
yii\base\Configurable
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/web/UploadedFile.php

UploadedFile represents the information for an uploaded file.

Public Properties
Property Type Description Defined By
$error integer An error code describing the status of this file uploading. yii\web\UploadedFile
$name string The original name of the file being uploaded yii\web\UploadedFile
$size integer The actual size of the uploaded file in bytes yii\web\UploadedFile
$tempName string The path of the uploaded file on the server. yii\web\UploadedFile
$type string The MIME-type of the uploaded file (such as "image/gif"). yii\web\UploadedFile
Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. 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() Returns the fully qualified name of this class. yii\base\BaseObject
getBaseName() yii\web\UploadedFile
getExtension() yii\web\UploadedFile
getHasError() yii\web\UploadedFile
getInstance() Returns an uploaded file for the given model attribute. yii\web\UploadedFile
getInstanceByName() Returns an instance of the specified uploaded file. The name can be a plain string or a string like an array element (e.g. 'Post[imageFile]', or 'Post[0][imageFile]'). craft\web\UploadedFile
getInstances() Returns all uploaded files for the given model attribute. yii\web\UploadedFile
getInstancesByName() Returns an array of instances starting with specified array name. craft\web\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() Cleans up the loaded UploadedFile instances. yii\web\UploadedFile
saveAs() Saves the uploaded file. yii\web\UploadedFile
saveAsTempFile() Saves the uploaded file to a temp location. craft\web\UploadedFile

Method Details

getInstanceByName() public static method #

Returns an instance of the specified uploaded file. The name can be a plain string or a string like an array element (e.g. 'Post[imageFile]', or 'Post[0][imageFile]').

public static static, null getInstanceByName ( $name, \craft\web\bool $ensureTempFileExists true )
$name string The name of the file input field
$ensureTempFileExists boolean Whether to only return the instance if its temp files still exists
return static, null The instance of the uploaded file. null is returned if no file is uploaded for the specified name.

getInstancesByName() public static method #

Returns an array of instances starting with specified array name.

If multiple files were uploaded and saved as 'Files[0]', 'Files[1]', 'Files[n]'..., you can have them all by passing 'Files' as array name.

public static craft\web\UploadedFile[] getInstancesByName ( $name, $lookForSingleInstance true, $ensureTempFilesExist true )
$name string The name of the array of files
$lookForSingleInstance boolean If set to true, will look for a single instance of the given name.
$ensureTempFilesExist boolean Whether only instances whose temp files still exist should be returned.
return craft\web\UploadedFile[] The array of UploadedFile objects. Empty array is returned if no adequate upload was found. Please note that this array will contain all files from all subarrays regardless how deeply nested they are.

saveAsTempFile() public method #

Saves the uploaded file to a temp location.

See also $error.

public string, false saveAsTempFile ( \craft\web\bool $deleteTempFile true )
$deleteTempFile boolean Whether to delete the temporary file after saving. If true, you will not be able to save the uploaded file again in the current request.
return string, false The path to the temp file, or false if the file wasn't saved successfully