Inheritance | yii\web\UploadedFile » yii\base\Object |
---|---|
Implements | yii\base\Configurable |
Available since version | 2.0 |
Source Code | https://github.com/yiisoft/yii2/blob/master/framework/web/UploadedFile.php |
UploadedFile represents the information for an uploaded file.
You can call getInstance() to retrieve the instance of an uploaded file, and then use saveAs() to save it on the server. You may also query other information about the file, including $name, $tempName, $type, $size and $error.
For more details and usage information on UploadedFile, see the guide article on handling uploads.
Property | Type | Description | Defined By |
---|---|---|---|
$baseName | string | Original file base name | yii\web\UploadedFile |
$error | integer | An error code describing the status of this file uploading. | yii\web\UploadedFile |
$extension | string | File extension | yii\web\UploadedFile |
$hasError | boolean | Whether there is an error with the uploaded file. | 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 |
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | yii\base\Object |
__construct() | Constructor. | yii\base\Object |
__get() | Returns the value of an object property. | yii\base\Object |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\Object |
__set() | Sets value of an object property. | yii\base\Object |
__toString() | String output. | yii\web\UploadedFile |
__unset() | Sets an object property to null. | yii\base\Object |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\Object |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\Object |
className() | Returns the fully qualified name of this class. | yii\base\Object |
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 uploaded file according to the given file input name. | yii\web\UploadedFile |
getInstances() | Returns all uploaded files for the given model attribute. | yii\web\UploadedFile |
getInstancesByName() | Returns an array of uploaded files corresponding to the specified file input name. | yii\web\UploadedFile |
hasMethod() | Returns a value indicating whether a method is defined. | yii\base\Object |
hasProperty() | Returns a value indicating whether a property is defined. | yii\base\Object |
init() | Initializes the object. | yii\base\Object |
reset() | Cleans up the loaded UploadedFile instances. | yii\web\UploadedFile |
saveAs() | Saves the uploaded file. | yii\web\UploadedFile |
Original file base name
public string getBaseName ( )
An error code describing the status of this file uploading.
See also http://www.php.net/manual/en/features.file-upload.errors.php.
public integer $error = null
File extension
public string getExtension ( )
Whether there is an error with the uploaded file. Check $error for detailed error code information.
public boolean getHasError ( )
The original name of the file being uploaded
public string $name = null
The actual size of the uploaded file in bytes
public integer $size = null
The path of the uploaded file on the server. Note, this is a temporary file which will be automatically deleted by PHP after the current request is processed.
public string $tempName = null
The MIME-type of the uploaded file (such as "image/gif"). Since this MIME type is not checked on the server-side, do not take this value for granted. Instead, use yii\helpers\FileHelper::getMimeType() to determine the exact MIME type.
public string $type = null
String output.
This is PHP magic method that returns string representation of an object. The implementation here returns the uploaded file's name.
public string __toString ( ) | ||
---|---|---|
return | string |
The string representation of the object |
public string getBaseName ( ) | ||
---|---|---|
return | string |
Original file base name |
public string getExtension ( ) | ||
---|---|---|
return | string |
File extension |
public boolean getHasError ( ) | ||
---|---|---|
return | boolean |
Whether there is an error with the uploaded file. Check $error for detailed error code information. |
Returns an uploaded file for the given model attribute.
The file should be uploaded using yii\widgets\ActiveField::fileInput().
See also getInstanceByName().
public static yii\web\UploadedFile getInstance ( $model, $attribute ) | ||
---|---|---|
$model | yii\base\Model |
The data model |
$attribute | string |
The attribute name. The attribute name may contain array indexes. For example, '[1]file' for tabular file uploading; and 'file[1]' for an element in a file array. |
return | yii\web\UploadedFile |
The instance of the uploaded file. Null is returned if no file is uploaded for the specified model attribute. |
Returns an uploaded file according to the given file input name.
The name can be a plain string or a string like an array element (e.g. 'Post[imageFile]', or 'Post[0][imageFile]').
public static null|yii\web\UploadedFile getInstanceByName ( $name ) | ||
---|---|---|
$name | string |
The name of the file input field. |
return | null|yii\web\UploadedFile |
The instance of the uploaded file. Null is returned if no file is uploaded for the specified name. |
Returns all uploaded files for the given model attribute.
public static yii\web\UploadedFile[] getInstances ( $model, $attribute ) | ||
---|---|---|
$model | yii\base\Model |
The data model |
$attribute | string |
The attribute name. The attribute name may contain array indexes for tabular file uploading, e.g. '[1]file'. |
return | yii\web\UploadedFile[] |
Array of UploadedFile objects. Empty array is returned if no available file was found for the given attribute. |
Returns an array of uploaded files corresponding to the specified file input name.
This is mainly used when multiple files were uploaded and saved as 'files[0]', 'files[1]', 'files[n]'..., and you can retrieve them all by passing 'files' as the name.
public static yii\web\UploadedFile[] getInstancesByName ( $name ) | ||
---|---|---|
$name | string |
The name of the array of files |
return | yii\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 sub-arrays regardless how deeply nested they are. |
Cleans up the loaded UploadedFile instances.
This method is mainly used by test scripts to set up a fixture.
public static void reset ( ) |
---|
Saves the uploaded file.
Note that this method uses php's move_uploaded_file() method. If the target file $file
already exists, it will be overwritten.
See also $error.
public boolean saveAs ( $file, $deleteTempFile = true ) | ||
---|---|---|
$file | string |
The file path used to save the uploaded file |
$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 | boolean |
True whether the file is saved successfully |
© 2008–2017 by Yii Software LLC
Licensed under the three clause BSD license.
http://www.yiiframework.com/doc-2.0/yii-web-uploadedfile.html