重构默认本地上传组件;

This commit is contained in:
2022-08-22 11:51:19 +08:00
parent b0ffb84fd6
commit e0d00e4422
5 changed files with 90 additions and 24 deletions

View File

@@ -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",

View File

@@ -24,7 +24,13 @@
<tip>设置允许上传大小。</tip>
</div>
</div>
<div class="layui-form-item show-type-item local_public">
<label class="layui-form-label">站点域名</label>
<div class="layui-input-block">
<input type="text" name="local_domain" class="layui-input" placeholder="请输入站点域名" value="{:sysconfig('upload','local_domain')}">
<tip>例子:{$Request.domain},如果不填写,那么自动获取当前站点域名,但是在命令行调用上传时不能正确生成地址。</tip>
</div>
</div>
<div class="layui-form-item show-type-item alioss">
<label class="layui-form-label required">公钥信息</label>
<div class="layui-input-block">

View File

@@ -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;
@@ -129,4 +131,25 @@ class UploadService
}
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;
}
}

View File

@@ -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',
],

View File

@@ -0,0 +1,30 @@
<?php
namespace think\filesystem\driver;
use think\facade\Request;
class LocalPublic extends Local
{
public function url(string $path): string
{
$url = sysconfig('upload', 'local_domain');
if (empty($url)) {
$host = Request::host();
if (!empty($host)) {
$url = Request::domain();
}
}
if (isset($this->config['url'])) {
$url = trim($url, '/') . '/' . trim($this->config['url'], '/');
}
if (isset($url)) {
return $this->concatPathToUrl($url, $path);
}
return parent::url($path);
}
}