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
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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