yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

FileValidator not validate #2330

Closed mitalcoi closed 10 years ago

mitalcoi commented 10 years ago

my AR:

    public $pic_hold;
        ......
    public function rules()
    {
        return [
            ['pic_hold', 'file', 'types' => ['gif']],
        ];
    }

and my view:

            <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
            <?= $form->field($model, 'pic_hold')->fileInput() ?>
            <?php ActiveForm::end(); ?>

If i trying to save jpeg, bmp, pdf, txt files - all of them succesful saving.

mitalcoi commented 10 years ago

i founded reason.if i write this in my controller:

        $model->load($_POST);
        $model->pic_hold=UploadedFile::getInstance($model, 'pic_hold');

everything works.

qiangxue commented 10 years ago

Yes, this is the expected usage.