There is a project on Yii2, there is a form with a file upload, for uploading a file I use this extension yii2-dropzone

There are no errors in the logs, but for some reason the files are not loaded.

Here is the widget output:

\kato\DropZone::widget([ 'options' => [ 'maxFilesize' => '2', 'url' => '/site/upload', // upload url ], 'clientEvents' => [ 'complete' => "function(file){console.log(file)}", 'removedfile' => "function(file){alert(file.name + ' is removed')}" ], ]); 

and code in the controller

  public function actionUpload(){ $fileName = 'upFile'; $uploadPath = '/var/www/ppms/web/site/upload'; if (isset($_FILES[$fileName])) { $file = \yii\web\UploadedFile::getInstanceByName($fileName); //Print file data print_r($file); if ($file->saveAs($uploadPath . '/' . $file->name)) { //Now save file data to database echo \yii\helpers\Json::encode($file); } } return false; } 

    1 answer 1

    See in the comments to the post: http://www.digitalaholic.com/upload-files-yii2-dropzone/

     $csrfToken = \Yii::$app->request->getCsrfToken(); echo \kato\DropZone::widget([ 'options' => [ 'url' => \Yii::$app->getUrlManager()->createUrl(['storage/upload']) ], 'clientEvents' => [ 'sending' => "function(file, xhr, formData) { formData.append('_csrf', '{$csrfToken}'); }", ]]); 
    • Welcome to Stack Overflow in Russian ! here it is customary to give a complete answer, and references are given only as a supplement / illustration. - aleksandr barakin
    • Please try to publish detailed answers containing a specific example of the minimum solution, supplementing them with a link to the source. Answers –references (as well as comments) do not add knowledge to the Runet. - Nicolas Chabanovsky