PHP 클래스 yii\web\UploadedFile
You can call
UploadedFile::getInstance to retrieve the instance of an uploaded file,
and then use
UploadedFile::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.
파일 보기
프로젝트 열기: yiisoft/yii2
1 사용 예제들
공개 프로퍼티들
프로퍼티 |
타입 |
설명 |
|
$error |
|
an error code describing the status of this file uploading. |
|
$name |
|
the original name of the file being uploaded |
|
$size |
|
the actual size of the uploaded file in bytes |
|
$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. |
|
$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. |
|
공개 메소드들
비공개 메소드들
메소드 상세
This is PHP magic method that returns string representation of an object.
The implementation here returns the uploaded file's name.
public getHasError ( ) : boolean |
리턴 |
boolean |
whether there is an error with the uploaded file.
Check [[error]] for detailed error code information. |
The file should be uploaded using [[\yii\widgets\ActiveField::fileInput()]].
public static getInstance ( Model $model, string $attribute ) : UploadedFile |
$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. |
리턴 |
UploadedFile |
the instance of the uploaded file.
Null is returned if no file is uploaded for the specified model attribute. |
getInstanceByName()
공개 정적인 메소드
The name can be a plain string or a string like an array element (e.g. 'Post[imageFile]', or 'Post[0][imageFile]').
public static getInstanceByName ( string $name ) : null | UploadedFile |
$name |
string |
the name of the file input field. |
리턴 |
null | 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 getInstances ( Model $model, string $attribute ) : UploadedFile[] |
$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'. |
리턴 |
UploadedFile[] |
array of UploadedFile objects.
Empty array is returned if no available file was found for the given attribute. |
getInstancesByName()
공개 정적인 메소드
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 getInstancesByName ( string $name ) : UploadedFile[] |
$name |
string |
the name of the array of files |
리턴 |
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. |
This method is mainly used by test scripts to set up a fixture.
Note that this method uses php's move_uploaded_file() method. If the target file $file
already exists, it will be overwritten.
public saveAs ( string $file, boolean $deleteTempFile = true ) : boolean |
$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. |
리턴 |
boolean |
true whether the file is saved successfully |
프로퍼티 상세
an error code describing the status of this file uploading.
the original name of the file being uploaded
the actual size of the uploaded file in bytes
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.
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.