没有命名空间的类 yii yii\base yii\behaviors yii\caching yii\captcha yii\console yii\console\controllers yii\console\widgets yii\data yii\db yii\db\conditions yii\db\cubrid yii\db\cubrid\conditions yii\db\mssql yii\db\mssql\conditions yii\db\mysql yii\db\oci yii\db\oci\conditions yii\db\pgsql yii\db\sqlite yii\db\sqlite\conditions yii\di yii\filters yii\filters\auth yii\grid yii\helpers yii\i18n yii\log yii\mail yii\mutex yii\rbac yii\rest yii\test yii\validators yii\web yii\widgets

Class yii\web\UploadedFile

继承yii\web\UploadedFile » yii\base\BaseObject
实现yii\base\Configurable
可用版本自2.0
源码 https://github.com/yiichina/yii2/blob/api/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.

公共属性

隐藏继承的属性

属性类型描述被定义在
$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

公共方法

隐藏继承的方法

方法描述被定义在
__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 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\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

属性详情

$baseName 公共 只读 属性

Original file base name

public string getBaseName ( )
$error 公共 属性

An error code describing the status of this file uploading.

参见 http://www.php.net/manual/en/features.file-upload.errors.php.

public integer $error null
$extension 公共 只读 属性

File extension

public string getExtension ( )
$hasError 公共 只读 属性

Whether there is an error with the uploaded file. Check $error for detailed error code information.

public boolean getHasError ( )
$name 公共 属性

The original name of the file being uploaded

public string $name null
$size 公共 属性

The actual size of the uploaded file in bytes

public integer $size null
$tempName 公共 属性

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
$type 公共 属性

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

方法详情

__toString() 公共 方法

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

getBaseName() 公共 方法

public string getBaseName()
return string

Original file base name

getExtension() 公共 方法

public string getExtension()
return string

File extension

getHasError() 公共 方法

public boolean getHasError()
return boolean

Whether there is an error with the uploaded file. Check $error for detailed error code information.

getInstance() 公共 静态 方法

Returns an uploaded file for the given model attribute.

The file should be uploaded using yii\widgets\ActiveField::fileInput().

参见 getInstanceByName().

public static null|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 null|yii\web\UploadedFile

The instance of the uploaded file. Null is returned if no file is uploaded for the specified model attribute.

getInstanceByName() 公共 静态 方法

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.

getInstances() 公共 静态 方法

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.

getInstancesByName() 公共 静态 方法

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.

reset() 公共 静态 方法

Cleans up the loaded UploadedFile instances.

This method is mainly used by test scripts to set up a fixture.

public static void reset()
saveAs() 公共 方法

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.

参见 $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