没有命名空间的类 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\MultipartFormDataParser

继承yii\web\MultipartFormDataParser » yii\base\BaseObject
实现yii\base\Configurable, yii\web\RequestParserInterface
可用版本自2.0.10
源码 https://github.com/yiichina/yii2/blob/api/framework/web/MultipartFormDataParser.php

MultipartFormDataParser parses content encoded as 'multipart/form-data'.

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 yii\web\Request::$parsers in the following way:

return [
    'components' => [
        'request' => [
            'parsers' => [
                'multipart/form-data' => 'yii\web\MultipartFormDataParser'
            ],
        ],
        // ...
    ],
    // ...
];

Method 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 yii\web\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:

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 yii\web\UploadedFile::saveAs() will fail as well.

公共属性

隐藏继承的属性

属性类型描述被定义在
$force boolean Whether to parse raw body even for 'POST' request and $_FILES already populated. yii\web\MultipartFormDataParser
$uploadFileMaxCount integer Maximum upload files count. yii\web\MultipartFormDataParser
$uploadFileMaxSize integer Upload file max size in bytes. yii\web\MultipartFormDataParser

公共方法

隐藏继承的方法

方法描述被定义在
__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
__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
getUploadFileMaxCount() yii\web\MultipartFormDataParser
getUploadFileMaxSize() yii\web\MultipartFormDataParser
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
parse() Parses a HTTP request body. yii\web\MultipartFormDataParser
setUploadFileMaxCount() yii\web\MultipartFormDataParser
setUploadFileMaxSize() yii\web\MultipartFormDataParser

属性详情

$force 公共 属性 (自版本 2.0.13 可用)

Whether to parse raw body even for 'POST' request and $_FILES already populated. By default this option is disabled saving performance for 'POST' requests, which are already processed by PHP automatically.

Note: if this option is enabled, value of $_FILES will be reset on each parse.

public boolean $force false
$uploadFileMaxCount 公共 属性

Maximum upload files count.

public integer getUploadFileMaxCount ( )
public void setUploadFileMaxCount ( $uploadFileMaxCount )
$uploadFileMaxSize 公共 属性

Upload file max size in bytes.

public integer getUploadFileMaxSize ( )
public void setUploadFileMaxSize ( $uploadFileMaxSize )

方法详情

getUploadFileMaxCount() 公共 方法

public integer getUploadFileMaxCount()
return integer

Maximum upload files count.

getUploadFileMaxSize() 公共 方法

public integer getUploadFileMaxSize()
return integer

Upload file max size in bytes.

parse() 公共 方法

Parses a HTTP request body.

public array parse($rawBody, $contentType)
$rawBody string

The raw HTTP request body.

$contentType string

The content type specified for the request body.

return array

Parameters parsed from the request body

setUploadFileMaxCount() 公共 方法

public void setUploadFileMaxCount($uploadFileMaxCount)
$uploadFileMaxCount integer

Maximum upload files count.

setUploadFileMaxSize() 公共 方法

public void setUploadFileMaxSize($uploadFileMaxSize)
$uploadFileMaxSize integer

Upload file max size in bytes.