From 27ac17f224f1198d82092bbb6aeaab49fa3c9028 Mon Sep 17 00:00:00 2001 From: Anyon Date: Tue, 24 Jul 2018 17:30:23 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=E4=BF=AE=E6=94=B9=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0=E5=90=8E=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Plugs.php | 31 ++++++++++++++------------ 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/application/admin/controller/Plugs.php b/application/admin/controller/Plugs.php index 8e400be48..9a894d9b8 100644 --- a/application/admin/controller/Plugs.php +++ b/application/admin/controller/Plugs.php @@ -59,8 +59,9 @@ class Plugs extends BasicAdmin if (!$file->checkExt(strtolower(sysconf('storage_local_exts')))) { return json(['code' => 'ERROR', 'msg' => '文件上传类型受限']); } - $ext = strtolower(pathinfo($file->getInfo('name'), 4)); $names = str_split($this->request->post('md5'), 16); + $ext = strtolower(pathinfo($file->getInfo('name'), 4)); + $ext = $ext ? $ext : 'tmp'; $filename = "{$names[0]}/{$names[1]}.{$ext}"; // 文件上传Token验证 if ($this->request->post('token') !== md5($filename . session_id())) { @@ -84,21 +85,22 @@ class Plugs extends BasicAdmin public function upstate() { $post = $this->request->post(); - $filename = join('/', str_split($post['md5'], 16)) . '.' . strtolower(pathinfo($post['filename'], 4)); + $ext = strtolower(pathinfo($post['filename'], 4)); + $filename = join('/', str_split($post['md5'], 16)) . '.' . ($ext ? $ext : 'tmp'); // 检查文件是否已上传 if (($site_url = FileService::getFileUrl($filename))) { - $this->result(['site_url' => $site_url], 'IS_FOUND'); + return json(['data' => ['site_url' => $site_url], 'code' => "IS_FOUND"]); } // 需要上传文件,生成上传配置参数 - $config = ['uptype' => $post['uptype'], 'file_url' => $filename]; + $data = ['uptype' => $post['uptype'], 'file_url' => $filename]; switch (strtolower($post['uptype'])) { case 'local': - $config['server'] = FileService::getUploadLocalUrl(); - $config['token'] = md5($filename . session_id()); + $data['token'] = md5($filename . session_id()); + $data['server'] = FileService::getUploadLocalUrl(); break; case 'qiniu': - $config['server'] = FileService::getUploadQiniuUrl(true); - $config['token'] = $this->_getQiniuToken($filename); + $data['token'] = $this->_getQiniuToken($filename); + $data['server'] = FileService::getUploadQiniuUrl(true); break; case 'oss': $time = time() + 3600; @@ -106,13 +108,14 @@ class Plugs extends BasicAdmin 'expiration' => date('Y-m-d', $time) . 'T' . date('H:i:s', $time) . '.000Z', 'conditions' => [['content-length-range', 0, 1048576000]], ]; - $config['server'] = FileService::getUploadOssUrl(); - $config['policy'] = base64_encode(json_encode($policyText)); - $config['site_url'] = FileService::getBaseUriOss() . $filename; - $config['signature'] = base64_encode(hash_hmac('sha1', $config['policy'], sysconf('storage_oss_secret'), true)); - $config['OSSAccessKeyId'] = sysconf('storage_oss_keyid'); + $data['server'] = FileService::getUploadOssUrl(); + $data['policy'] = base64_encode(json_encode($policyText)); + $data['site_url'] = FileService::getBaseUriOss() . $filename; + $data['signature'] = base64_encode(hash_hmac('sha1', $data['policy'], sysconf('storage_oss_secret'), true)); + $data['OSSAccessKeyId'] = sysconf('storage_oss_keyid'); + break; } - $this->result($config, 'NOT_FOUND'); + return json(['data' => $data, 'code' => "NOT_FOUND"]); } /**