From bfcb4ad321df407b964d07e340d4054ba44556ea Mon Sep 17 00:00:00 2001 From: augushong Date: Mon, 11 Jul 2022 18:39:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=A7=8B=E8=85=BE=E8=AE=AF=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Ajax.php | 1 + app/common.php | 3 ++ app/common/service/UploadService.php | 2 +- composer.json | 3 +- composer.lock | 39 +++++++++++++++++++++++- config/filesystem.php | 3 ++ extend/think/filesystem/driver/Txcos.php | 36 ++++++++++++++++++++++ 7 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 extend/think/filesystem/driver/Txcos.php diff --git a/app/admin/controller/Ajax.php b/app/admin/controller/Ajax.php index ddf574a..d9ebdb1 100644 --- a/app/admin/controller/Ajax.php +++ b/app/admin/controller/Ajax.php @@ -71,6 +71,7 @@ class Ajax extends AdminController $result = $upload_service->save($data['file']); } catch (\Exception $e) { + throw $e; $this->error($e->getMessage()); } diff --git a/app/common.php b/app/common.php index 5070225..a422c90 100644 --- a/app/common.php +++ b/app/common.php @@ -241,6 +241,9 @@ function build_upload_url($url) case 'alioss': $prefix_url = $config['alioss_domain']; break; + // case 'alioss': + // $prefix_url = $config['alioss_domain']; + // break; default: # code... diff --git a/app/common/service/UploadService.php b/app/common/service/UploadService.php index 894c4fe..0176b97 100644 --- a/app/common/service/UploadService.php +++ b/app/common/service/UploadService.php @@ -70,7 +70,7 @@ class UploadService $save_name = Filesystem::disk($this->uploadType)->putFile('upload', $file, function () { - return date('Ymd') . DIRECTORY_SEPARATOR . uniqid(); + return date('Ymd') . '/' . uniqid(); }); $url = build_upload_url($save_name); diff --git a/composer.json b/composer.json index 59b8d3f..c31ffa8 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "phpoffice/phpspreadsheet": "^1.22", "topthink/think-migration": "^3.0", "overtrue/flysystem-qiniu": "*", - "xxtime/flysystem-aliyun-oss": "^1.5" + "xxtime/flysystem-aliyun-oss": "^1.5", + "chunpat/flysystem-tencent-cos": "^0.0.1" }, "require-dev": { "symfony/var-dumper": "^4.2", diff --git a/composer.lock b/composer.lock index e09b8d2..a26e9c6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "111f94878583850a9fed799619afc3d7", + "content-hash": "2dae06d14067806fb0de04359c23b7e7", "packages": [ { "name": "aliyuncs/oss-sdk-php", @@ -46,6 +46,43 @@ "homepage": "http://www.aliyun.com/product/oss/", "time": "2022-05-13T07:41:28+00:00" }, + { + "name": "chunpat/flysystem-tencent-cos", + "version": "0.0.1", + "source": { + "type": "git", + "url": "https://github.com/chunpat/flysystem-tencent-cos.git", + "reference": "ef53f4aea50614055b4ea785e742a09a011b9c0c" + }, + "dist": { + "type": "zip", + "url": "https://repo.huaweicloud.com/repository/php/chunpat/flysystem-tencent-cos/0.0.1/chunpat-flysystem-tencent-cos-0.0.1.zip", + "reference": "ef53f4aea50614055b4ea785e742a09a011b9c0c", + "shasum": "" + }, + "require": { + "league/flysystem": "^1.0", + "php": ">=7.1.0", + "qcloud/cos-sdk-v5": "^2.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Chunpat\\FlysystemTencentCos\\": "src" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "chunpat", + "email": "chunpat@163.com" + } + ], + "description": "Package description here.", + "time": "2020-06-22T17:18:34+00:00" + }, { "name": "doctrine/annotations", "version": "1.13.3", diff --git a/config/filesystem.php b/config/filesystem.php index 9ced505..58a34ea 100644 --- a/config/filesystem.php +++ b/config/filesystem.php @@ -27,6 +27,9 @@ return [ 'alioss' => [ 'type' => 'Alioss' ], + 'txcos' => [ + 'type' => 'Txcos' + ], // 更多的磁盘配置信息 ], ]; diff --git a/extend/think/filesystem/driver/Txcos.php b/extend/think/filesystem/driver/Txcos.php new file mode 100644 index 0000000..3773292 --- /dev/null +++ b/extend/think/filesystem/driver/Txcos.php @@ -0,0 +1,36 @@ + $region, + 'schema' => 'https', //协议头部,默认为http + 'credentials' => array( + 'secretId' => $secretId, + 'secretKey' => $secretKey + ), + 'signHost' => false + ) + ); + $bucket = sysconfig('upload', 'tecos_bucket'); //存储桶名称 格式:BucketName-APPID + + + + $adapter = new \Chunpat\FlysystemTencentCos\Adapter($cosClient, $bucket); + + return $adapter; + } +}