3

i am new yii2, so i have this problem. i want to use fileinput so i add fileinput this url http://www.yiiframework.com/doc-2.0/guide-input-file-upload.html if i create new model with file input (select video) and if i delete item in model so:** Ber Request (#400) Unable to verify your data submission. if i select image, it work ok how to upload video in yii2 ?

my log:

exception 'yii\web\BadRequestHttpException' with message 'Unable to verify your data submission.' in C:\xampp\htdocs\project\vendor\yiisoft\yii2\web\Controller.php:110
Stack trace:
C:\xampp\htdocs\project\vendor\yiisoft\yii2\base\Controller.php(149): yii\web\Controller->beforeAction(Object(yii\base\InlineAction))
C:\xampp\htdocs\project\vendor\yiisoft\yii2\base\Module.php(455): yii\base\Controller->runAction('delete', Array)
C:\xampp\htdocs\project\vendor\yiisoft\yii2\web\Application.php(84): yii\base\Module->runAction('music/delete', Array)
C:\xampp\htdocs\project\vendor\yiisoft\yii2\base\Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
C:\xampp\htdocs\project\web\index.php(12): yii\base\Application->run()
{main}

Please, help me? Thank !

Chinmay Waghmare
  • 5,368
  • 2
  • 43
  • 68
Clever
  • 401
  • 1
  • 6
  • 17

2 Answers2

9

It's code from core YII2.

if ($this->enableCsrfValidation && Yii::$app->getErrorHandler()->exception === null && !Yii::$app->getRequest()->validateCsrfToken()) {
    throw new BadRequestHttpException(Yii::t('yii', 'Unable to verify your data submission.'));
}

Try turn off csrf validation.

MyController extends Controller {
    public $enableCsrfValidation = false;
}
Konstantin
  • 566
  • 4
  • 9
  • thank, i found answer. this problem - my php configiration. it don't access to upload 2 M files (php >> php.ini file) – Clever Jul 10 '15 at 03:45
  • It works for me, thanks a lot. But why we need to disable csrf validation, can anyone explain where we need to enable Csrf validation and where we need to disable Csrf validation? – Nivetha Jaishankar Apr 25 '17 at 13:10
  • Best way is always use csrf. This sample just helps to understand problem. How to handle csrf you can see there: http://stackoverflow.com/a/28479422/2655835 – Konstantin Apr 26 '17 at 14:44
0

See Upgrade instructions:

[https://github.com/yiisoft/yii2/blob/master/framework/UPGRADE.md#upgrade-from-yii-20-beta][1]

Please update your main layout file by adding this line in the section: <?= Html::csrfMetaTags() ?> . This change is needed because yii\web\View no longer automatically generates CSRF meta tags due to issue #3358

Gowtham
  • 149
  • 8
  • I have this line in my layout head section, but my app.log is full of BadRequestHttpException entries, even though the form data is stored normally. What am I doing wrong? – mogilka Aug 07 '17 at 10:01