diff --git a/app/admin/service/initAdminData/SystemConfig.php b/app/admin/service/initAdminData/SystemConfig.php index 2234530..5cb2b2d 100644 --- a/app/admin/service/initAdminData/SystemConfig.php +++ b/app/admin/service/initAdminData/SystemConfig.php @@ -224,6 +224,13 @@ $ul_system_config = array( "remark" => "访问域名", "sort" => 0, ), + array( + "name" => "txcos_domain", + "group" => "upload", + "value" => "填你的", + "remark" => "访问域名", + "sort" => 0, + ), array( "name" => "file", "group" => "site", diff --git a/app/admin/view/system/config/upload.html b/app/admin/view/system/config/upload.html index 895ab17..e9e807b 100644 --- a/app/admin/view/system/config/upload.html +++ b/app/admin/view/system/config/upload.html @@ -4,7 +4,7 @@
{foreach ['local_public'=>'本地存储','alioss'=>'阿里云oss','qnoss'=>'七牛云oss','txcos'=>'腾讯云cos'] as $key=>$val} - + {/foreach}
@@ -24,8 +24,14 @@ 设置允许上传大小。 - -
+
+ +
+ + 例子:{$Request.domain},如果不填写,那么自动获取当前站点域名,但是在命令行调用上传时不能正确生成地址。 +
+
+
@@ -33,7 +39,7 @@
-
+
@@ -41,7 +47,7 @@
-
+
@@ -49,7 +55,7 @@
-
+
@@ -57,7 +63,7 @@
-
+
@@ -65,7 +71,7 @@
-
+
@@ -73,7 +79,7 @@
-
+
@@ -81,7 +87,7 @@
-
+
@@ -89,14 +95,14 @@
-
+
例子:ulthon-admin-1251997243
-
+
@@ -104,7 +110,7 @@
-
+
@@ -112,7 +118,7 @@
-
+
@@ -120,7 +126,7 @@
-
+
@@ -128,7 +134,7 @@
-
+
diff --git a/app/common/service/UploadService.php b/app/common/service/UploadService.php index 450a30f..049b1da 100644 --- a/app/common/service/UploadService.php +++ b/app/common/service/UploadService.php @@ -3,6 +3,8 @@ namespace app\common\service; use app\admin\model\SystemUploadfile; +use app\common\tools\PathTools; +use think\facade\App; use think\facade\Filesystem; use think\facade\Validate; use think\File; @@ -97,16 +99,16 @@ class UploadService } - $save_name = Filesystem::disk($this->uploadType)->putFile($upload_dir, $file, function () use ($save_name,$file) { + $save_name = Filesystem::disk($this->uploadType)->putFile($upload_dir, $file, function () use ($save_name, $file) { if (!is_null($save_name)) { $ext_name = $file->extension(); - if(empty($ext_name)){ + if (empty($ext_name)) { return $save_name; } - $list_name = explode('.',$save_name); + $list_name = explode('.', $save_name); array_pop($list_name); @@ -123,10 +125,31 @@ class UploadService $model_file->sha1 = $file->sha1(); $model_file->file_size = $file->getSize(); - + if (!$disable_model) { $model_file->save(); } return $model_file; } + + public function saveUrlFile($url, string $save_name = null, $force_save = false, $upload_dir = 'upload', $disable_model = false) + { + + $runtime_path = App::getRuntimePath() . 'upload/temp/' . basename($url); + + PathTools::intiDir($runtime_path); + + + $file_content = file_get_contents($url); + + file_put_contents($runtime_path, $file_content); + + $file = new File($runtime_path); + + $response = $this->save($file, $save_name, $force_save, $upload_dir, $disable_model); + + unlink($runtime_path); + + return $response; + } } diff --git a/config/filesystem.php b/config/filesystem.php index 83d0be5..32d2b79 100644 --- a/config/filesystem.php +++ b/config/filesystem.php @@ -14,21 +14,21 @@ return [ ], 'local_public' => [ // 磁盘类型 - 'type' => 'local', + 'type' => 'LocalPublic', // 磁盘路径 'root' => app()->getRootPath() . 'public/storage', // 磁盘路径对应的外部URL路径 - 'url' => Request::domain() . '/storage', + 'url' => '/storage', // 可见性 'visibility' => 'public', ], 'local_static' => [ // 磁盘类型 - 'type' => 'local', + 'type' => 'LocalPublic', // 磁盘路径 'root' => app()->getRootPath() . 'public/static', // 磁盘路径对应的外部URL路径 - 'url' => Request::domain() . '/static', + 'url' => '/static', // 可见性 'visibility' => 'public', ], diff --git a/extend/think/filesystem/driver/LocalPublic.php b/extend/think/filesystem/driver/LocalPublic.php new file mode 100644 index 0000000..778dd12 --- /dev/null +++ b/extend/think/filesystem/driver/LocalPublic.php @@ -0,0 +1,30 @@ +config['url'])) { + $url = trim($url, '/') . '/' . trim($this->config['url'], '/'); + } + + if (isset($url)) { + return $this->concatPathToUrl($url, $path); + } + return parent::url($path); + } +}