diff --git a/service/app/admin/controller/UploadController.php b/service/app/admin/controller/UploadController.php new file mode 100644 index 00000000..5e88b520 --- /dev/null +++ b/service/app/admin/controller/UploadController.php @@ -0,0 +1,41 @@ +file("file"); + + if (!$file->isValid()) { + return $this->error(400, 'upload fail, code=' . $file->getUploadErrorCode()); + } + + $now = date_create(); + $savepath = sprintf("/uploads/%d/%s/%s", $request->admin->id, $now->format("YmdHisu"), $file->getUploadName()); + $file->move(public_path(). $savepath); + + $item = new Uploads(); + $item->admin_id = $request->admin->id; + $item->filesize = $file->getSize(); + $item->filepath = $savepath; + $item->mime = $file->getUploadMimeType(); + $item->create_at = $now->getTimestamp(); + $item->save(); + + return $this->success($savepath); + } +} \ No newline at end of file diff --git a/service/app/middleware/adminAuth.php b/service/app/middleware/adminAuth.php index b8548531..0cf77571 100644 --- a/service/app/middleware/adminAuth.php +++ b/service/app/middleware/adminAuth.php @@ -21,7 +21,8 @@ class adminAuth implements MiddlewareInterface //白名单 $url = [ '/admin/login', - 'admin/index/avatar' + 'admin/index/avatar', + 'admin/upload/index', ]; if(in_array($path, $url)) { return $next($request); diff --git a/service/app/model/Uploads.php b/service/app/model/Uploads.php new file mode 100644 index 00000000..6e553e26 --- /dev/null +++ b/service/app/model/Uploads.php @@ -0,0 +1,36 @@ +