Beispiel #1
0
 public function run($table, $id)
 {
     if (Yii::$app->request->isPost) {
         $model = new FileUploadModel();
         $model->id = $id;
         $model->tableId = $table;
         $model->files[] = UploadedFile::getInstanceByName('files');
         if ($model->upload()) {
             return $model->getLink();
         } else {
             return ['error' => 'Не удалось загрузить файл'];
         }
     }
 }
Beispiel #2
0
 public function actionAjaxUpload($table, $id)
 {
     if (Yii::$app->request->isPost) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $model = new FileUploadModel();
         $model->id = $id;
         $model->tableId = $table;
         $model->files[] = UploadedFile::getInstanceByName('files');
         $zz = rand(1, 10);
         if ($model->upload()) {
             return $this->getUploadedFilesInfo($model->uploadedIds);
         } else {
             return ['error' => $model->files[0]->baseName];
             $errors = [];
             foreach ($model->errors as $attr => $e) {
                 $errors = array_merge($e, $errors);
             }
             Yii::trace('Ошибка загрузки файла ' . \yii\helpers\VarDumper::dumpAsString($model->errors));
             return ['error' => implode(', ', $errors)];
         }
     }
 }