public function actionUpload()
 {
     $response = ['success' => false];
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $request = Yii::$app->getRequest();
     $dir = \skeeks\sx\Dir::runtimeTmp();
     $uploader = new \skeeks\widget\simpleajaxuploader\backend\FileUpload("imgfile");
     $file = $dir->newFile()->setExtension($uploader->getExtension());
     $originalName = $uploader->getFileName();
     $uploader->newFileName = $file->getBaseName();
     $result = $uploader->handleUpload($dir->getPath() . DIRECTORY_SEPARATOR);
     if (!$result) {
         $response["msg"] = $uploader->getErrorMsg();
         return $result;
     } else {
         $storageFile = Yii::$app->storage->upload($file, array_merge(["name" => "", "original_name" => $originalName]));
         if ($request->get('modelData') && is_array($request->get('modelData'))) {
             $storageFile->setAttributes($request->get('modelData'));
         }
         $storageFile->save(false);
         $response["success"] = true;
         $response["file"] = $storageFile;
         return $response;
     }
     return $response;
 }
 public function actionUpload()
 {
     $response = ['success' => false];
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $request = Yii::$app->getRequest();
     $dir = \skeeks\sx\Dir::runtimeTmp();
     $uploader = new \skeeks\widget\simpleajaxuploader\backend\FileUpload("imgfile");
     $file = $dir->newFile()->setExtension($uploader->getExtension());
     $originalName = $uploader->getFileName();
     $uploader->newFileName = $file->getBaseName();
     $result = $uploader->handleUpload($dir->getPath() . DIRECTORY_SEPARATOR);
     if (!$result) {
         $response["msg"] = $uploader->getErrorMsg();
         return $result;
     } else {
         $storageFile = Yii::$app->storage->upload($file, array_merge(["name" => "", "original_name" => $originalName]));
         if ($request->get('modelData') && is_array($request->get('modelData'))) {
             $storageFile->setAttributes($request->get('modelData'));
         }
         $storageFile->save(false);
         if ($group = $request->get("group")) {
             /**
              *
              * @var \skeeks\cms\models\helpers\ModelFilesGroup $group
              */
             $group = $model->getFilesGroups()->getComponent($group);
             if ($group) {
                 try {
                     $group->attachFile($storageFile)->save();
                 } catch (\yii\base\Exception $e) {
                     $response["msgError"] = $e->getMessage();
                 }
             }
         }
         $response["success"] = true;
         $response["file"] = $storageFile;
         return $response;
     }
     return $response;
 }