/**
  * Provides upload file
  * @return mixed
  */
 public function actionUpload($related = null, $itemId = null, $tempId = null)
 {
     $event = new \derekisbusy\filemanager\events\UploadEvent();
     $event->relatedClass = $this->module->relations[$related];
     $this->module->trigger(Module::EVENT_UPLOAD, $event);
     $relation = null;
     if (isset($related)) {
         if (!isset($this->module->relations[$related])) {
             throw new \yii\base\InvalidParamException();
         }
         $relation = $this->module->relations[$related];
     }
     $model = new Mediafile();
     $routes = $this->module->routes;
     $rename = $this->module->rename;
     if ($tempId) {
         $model->temp_id = $tempId;
     }
     $model->saveUploadedFile($routes, $rename, $related, $itemId);
     // create relations
     if ($related && $itemId) {
         $thru = new $this->module->relations[$related]['class']();
         $thru->{$relation['model_id']} = $itemId;
         $thru->{$relation['file_id']} = $model->id;
         $thru->save();
     }
     $bundle = FilemanagerAsset::register($this->view);
     if ($model->isImage()) {
         $model->createThumbs($routes, $this->module->thumbs);
     }
     Yii::$app->response->format = Response::FORMAT_JSON;
     $response = [];
     $response['files'][] = ['url' => $model->url, 'thumbnailUrl' => $model->getDefaultThumbUrl($bundle->baseUrl), 'name' => $model->filename, 'type' => $model->type, 'size' => $model->file->size, 'deleteUrl' => Url::to(['file/delete', 'id' => $model->id]), 'deleteType' => 'POST'];
     return $response;
 }