From 36ffb62bec4d3c68e2b0620a7dc8145e45f19d7d Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 9 Sep 2020 22:56:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Controllers/v3/FileController.php | 45 +++++++++++++++++++++ app/Admin/routes.php | 1 + 2 files changed, 46 insertions(+) create mode 100644 app/Admin/Controllers/v3/FileController.php diff --git a/app/Admin/Controllers/v3/FileController.php b/app/Admin/Controllers/v3/FileController.php new file mode 100644 index 0000000..a43dd17 --- /dev/null +++ b/app/Admin/Controllers/v3/FileController.php @@ -0,0 +1,45 @@ +disk('oss'); + + // 判断是否是删除文件请求 + if ($this->isDeleteRequest()) { + // 删除文件并响应 + return $this->deleteFileAndResponse($disk); + } + + // 获取上传的文件 + $file = $this->file(); + + // 获取上传的字段名称 + $column = $this->uploader()->upload_column; + + $extension = $file->getClientOriginalExtension(); + $fileName = md5(uniqid()).'.'.$extension; + + $dir = 'my-images'; + $newName = $fileName; + + $result = $disk->putFileAs($dir, $file, $newName); + + $path = "{$dir}/$newName"; + + $diskBak = $this->disk('public'); + + $diskBak->putFileAs($dir, $file, $newName); + + return $result + ? $this->responseUploaded($path, $disk->url($path)) + : $this->responseErrorMessage('文件上传失败'); + } +} diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 512b915..48b60cd 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -65,5 +65,6 @@ Route::group([ $router->any('/detail', 'ImsCjdcOrderMainController@orderDetail'); $router->resource('/horseman', 'LanzuServiceHorsemanController'); + $router->any('ops/files', 'v3\FileController@handle'); });