UploadedFile

Type
Class
Namespace
craft\web
Inherits
craft\web\UploadedFile » yii\web\UploadedFile (opens new window) » yii\base\BaseObject (opens new window)
Implements
yii\base\Configurable (opens new window)
Since
3.0.0

UploadedFile represents the information for an uploaded file.

View source (opens new window)

# Public Properties

Property Description
baseName (opens new window) string (opens new window) – Original file base name.
error (opens new window) integer (opens new window) – An error code describing the status of this file uploading.
extension (opens new window) string (opens new window) – File extension.
fullPath (opens new window) string (opens new window), null (opens new window) – The full path as submitted by the browser.
hasError (opens new window) boolean (opens new window) – Whether there is an error with the uploaded file.
mimeType string (opens new window), null (opens new window)
name (opens new window) string (opens new window) – The original name of the file being uploaded
size (opens new window) integer (opens new window) – The actual size of the uploaded file in bytes
tempName (opens new window) string (opens new window) – The path of the uploaded file on the server.
type (opens new window) string (opens new window) – The MIME-type of the uploaded file (such as "image/gif").

# mimeType

Type
string (opens new window), null (opens new window)
Default value
null
Access
Read-only
Since
3.1.7

View source (opens new window)

# Public Methods

Method Description
__call() (opens new window) Calls the named method which is not a class method.
__construct() (opens new window) UploadedFile constructor.
__get() (opens new window) Returns the value of an object property.
__isset() (opens new window) Checks if a property is set, i.e. defined and not null.
__set() (opens new window) Sets value of an object property.
__toString() (opens new window) String output.
__unset() (opens new window) Sets an object property to null.
canGetProperty() (opens new window) Returns a value indicating whether a property can be read.
canSetProperty() (opens new window) Returns a value indicating whether a property can be set.
className() (opens new window) Returns the fully qualified name of this class.
getBaseName() (opens new window)
getExtension() (opens new window)
getHasError() (opens new window)
getInstance() (opens new window) Returns an uploaded file for the given model attribute.
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]').
getInstances() (opens new window) Returns all uploaded files for the given model attribute.
getInstancesByName() Returns an array of instances starting with specified array name.
getMimeType() Returns the MIME type of the file, based on craft\helpers\FileHelper::getMimeType() rather than what the request told us.
hasMethod() (opens new window) Returns a value indicating whether a method is defined.
hasProperty() (opens new window) Returns a value indicating whether a property is defined.
init() (opens new window) Initializes the object.
reset() (opens new window) Cleans up the loaded UploadedFile instances.
saveAs() (opens new window) Saves the uploaded file.
saveAsTempFile() Saves the uploaded file to a temp location.

# 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]').

View source (opens new window)

Arguments

Returns

static, null (opens new window) – The instance of the uploaded file. null is returned if no file is uploaded for the specified name.

# getInstancesByName()

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.

View source (opens new window)

Arguments

Returns

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.

# getMimeType()

Since
3.1.7

Returns the MIME type of the file, based on craft\helpers\FileHelper::getMimeType() rather than what the request told us.

View source (opens new window)

Arguments

Returns

string (opens new window), null (opens new window)

Throws

# saveAsTempFile()

Saves the uploaded file to a temp location.

See also error (opens new window) View source (opens new window)

Arguments

  • $deleteTempFile (boolean (opens new window)) – 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.

Returns

string (opens new window), false (opens new window) – The path to the temp file, or false if the file wasn't saved successfully

# Protected Methods

Method Description
copyTempFile() (opens new window) Copy temporary file into file specified