here is the controller
public function actionCreate(){ $module=$this->module; $model= new MenuGet(); $uploadModel=new UploadImage(); if (Yii::$app->request->isAjax) { $request=Yii::$app->request; if($request->isPost){ $fileName = 'file'; if (isset($_FILES[$fileName])) { $file = \yii\web\UploadedFile::getInstanceByName($fileName); $uplImg=$uploadModel->upload($file ,$module); if ($uplImg) { return $this->render('create', [ 'model' => $model, 'module' => $module, 'uploadModel' => $uploadModel ]); } } } here is UploadImage
class UploadImage extends Model { public $file; public function rules() { return [ [['file'], 'file','skipOnEmpty' => true, 'extensions' => 'png, jpg, jpeg, gif'], ]; } public function upload($fileName,$module){ $basePath=date('Y').'/'.date('m'); $uploadPath =$module->imageDownloadPath.''.$basePath; if (file_exists($uploadPath)) { } else { mkdir($uploadPath, 0777, true); } $file = \yii\web\UploadedFile::getInstanceByName($fileName); $filenames=$this->traranslitImg($file->name); if ($this->validate()) { if(file_exists($uploadPath)) { } else { mkdir($uploadPath, 0777, true); } if ($this->file->saveAs($uploadPath . '/' . $filenames)){ $this->imagerisize($uploadPath, $filenames,$module); return true; }; } else { return var_dump($this->getErrors()); } } The picture is loaded through the dropzone but the answer comes
Exception 'Error' with message 'Call to a member function saveAs () on null'
in /var/www/magaz.lc/vendor/sirgalas/yii2-wordperss-menu/models/UploadImage.php:41
public $file;, and this is not initialization? - Sergalaspublic $file;- this announcement .....$file = БЛА БЛА БЛА;- initialization, i.e. assignment of a certain value - Alexey Shimansky