PHP Class yii\web\MultipartFormDataParser

This parser provides the fallback for the 'multipart/form-data' processing on non POST requests, for example: the one with 'PUT' request method. In order to enable this parser you should configure [[Request::parsers]] in the following way: php return [ 'components' => [ 'request' => [ 'parsers' => [ 'multipart/form-data' => 'yii\web\MultipartFormDataParser' ], ], ... ], ... ]; Method MultipartFormDataParser::parse of this parser automatically populates $_FILES with the files parsed from raw body. > Note: since this is a request parser, it will initialize $_FILES values on [[Request::getBodyParams()]]. Until this method is invoked, $_FILES array will remain empty even if there are submitted files in the request body. Make sure you have requested body params before any attempt to get uploaded file in case you are using this parser. Usage example: php use yii\web\UploadedFile; $restRequestData = Yii::$app->request->getBodyParams(); $uploadedFile = UploadedFile::getInstancesByName('photo'); $model = new Item(); $model->populate($restRequestData); copy($uploadedFile->tempName, '/path/to/file/storage/photo.jpg'); > Note: although this parser fully emulates regular structure of the $_FILES, related temporary files, which are available via tmp_name key, will not be recognized by PHP as uploaded ones. Thus functions like is_uploaded_file() and move_uploaded_file() will fail on them. This also means [[UploadedFile::saveAs()]] will fail as well.
Since: 2.0.10
Author: Paul Klimov ([email protected])
Inheritance: extends yii\base\Object, implements yii\web\RequestParserInterface
Show file Open project: yiisoft/yii2

Public Methods

Method Description
getUploadFileMaxCount ( ) : integer
getUploadFileMaxSize ( ) : integer
parse ( $rawBody, $contentType )
setUploadFileMaxCount ( integer $uploadFileMaxCount )
setUploadFileMaxSize ( integer $uploadFileMaxSize )

Private Methods

Method Description
addFile ( array &$files, string $name, array $info ) Adds file info to the uploaded files array by input name, e.g. Item[file].
addValue ( array &$array, string $name, mixed $value ) Adds value to the array by input name, e.g. Item[name].
getByteSize ( string $verboseSize ) : integer Gets the size in bytes from verbose size representation.
parseHeaders ( string $headerContent ) : array Parses content part headers.

Method Details

getUploadFileMaxCount() public method

public getUploadFileMaxCount ( ) : integer
return integer maximum upload files count.

getUploadFileMaxSize() public method

public getUploadFileMaxSize ( ) : integer
return integer upload file max size in bytes.

parse() public method

public parse ( $rawBody, $contentType )

setUploadFileMaxCount() public method

public setUploadFileMaxCount ( integer $uploadFileMaxCount )
$uploadFileMaxCount integer maximum upload files count.

setUploadFileMaxSize() public method

public setUploadFileMaxSize ( integer $uploadFileMaxSize )
$uploadFileMaxSize integer upload file max size in bytes.