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.
부터: 2.0
저자: Qiang Xue ([email protected])
상속: extends yii\base\Object
파일 보기 프로젝트 열기: 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.

공개 메소드들

메소드 설명
__toString ( ) : string String output.
getBaseName ( ) : string
getExtension ( ) : string
getHasError ( ) : boolean
getInstance ( Model $model, string $attribute ) : UploadedFile Returns an uploaded file for the given model attribute.
getInstanceByName ( string $name ) : null | UploadedFile Returns an uploaded file according to the given file input name.
getInstances ( Model $model, string $attribute ) : UploadedFile[] Returns all uploaded files for the given model attribute.
getInstancesByName ( string $name ) : UploadedFile[] Returns an array of uploaded files corresponding to the specified file input name.
reset ( ) Cleans up the loaded UploadedFile instances.
saveAs ( string $file, boolean $deleteTempFile = true ) : boolean Saves the uploaded file.

비공개 메소드들

메소드 설명
loadFiles ( ) : array Creates UploadedFile instances from $_FILE.
loadFilesRecursive ( string $key, mixed $names, mixed $tempNames, mixed $types, mixed $sizes, mixed $errors ) Creates UploadedFile instances from $_FILE recursively.

메소드 상세

__toString() 공개 메소드

This is PHP magic method that returns string representation of an object. The implementation here returns the uploaded file's name.
public __toString ( ) : string
리턴 string the string representation of the object

getBaseName() 공개 메소드

public getBaseName ( ) : string
리턴 string original file base name

getExtension() 공개 메소드

public getExtension ( ) : string
리턴 string file extension

getHasError() 공개 메소드

public getHasError ( ) : boolean
리턴 boolean whether there is an error with the uploaded file. Check [[error]] for detailed error code information.

getInstance() 공개 정적인 메소드

The file should be uploaded using [[\yii\widgets\ActiveField::fileInput()]].
또한 보기: getInstanceByName()
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.

reset() 공개 정적인 메소드

This method is mainly used by test scripts to set up a fixture.
public static reset ( )

saveAs() 공개 메소드

Note that this method uses php's move_uploaded_file() method. If the target file $file already exists, it will be overwritten.
또한 보기: error
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

프로퍼티 상세

$error 공개적으로 프로퍼티

an error code describing the status of this file uploading.
또한 보기: http://www.php.net/manual/en/features.file-upload.errors.php
public $error

$name 공개적으로 프로퍼티

the original name of the file being uploaded
public $name

$size 공개적으로 프로퍼티

the actual size of the uploaded file in bytes
public $size

$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 $tempName

$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 $type