From fa08383513b8d349d6f6b69e7bc8d18050595ad0 Mon Sep 17 00:00:00 2001 From: Anyon Date: Fri, 25 Dec 2020 16:22:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3=E4=BA=8C?= =?UTF-8?q?=E8=BF=9B=E5=88=B6=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/data/controller/api/auth/Center.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/data/controller/api/auth/Center.php b/app/data/controller/api/auth/Center.php index 8671c1d97..5690a5aa3 100644 --- a/app/data/controller/api/auth/Center.php +++ b/app/data/controller/api/auth/Center.php @@ -63,7 +63,7 @@ class Center extends Auth } /** - * 上传Base64图片 + * Base64 图片上传 */ public function image() { @@ -83,6 +83,29 @@ class Center extends Auth } } + /** + * 二进制文件上传 + * @throws \think\admin\Exception + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function upload() + { + $file = $this->request->file('file'); + if (empty($file)) $this->error('文件上传异常!'); + $extension = strtolower($file->getOriginalExtension()); + if (in_array($extension, ['php', 'sh'])) $this->error('禁止上传此类文件!'); + $bina = file_get_contents($file->getRealPath()); + $name = Storage::name($file->getPathname(), $extension, '', 'md5_file'); + $info = Storage::instance()->set($name, $bina, false, $file->getOriginalName()); + if (is_array($info) && isset($info['url'])) { + $this->success('文件上传成功!', $info); + } else { + $this->error('文件上传失败!'); + } + } + /** * 绑定用户邀请人 * @throws \think\Exception