mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-09 11:32:48 +08:00
重构默认本地上传组件;
This commit is contained in:
@@ -224,6 +224,13 @@ $ul_system_config = array(
|
|||||||
"remark" => "访问域名",
|
"remark" => "访问域名",
|
||||||
"sort" => 0,
|
"sort" => 0,
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
"name" => "txcos_domain",
|
||||||
|
"group" => "upload",
|
||||||
|
"value" => "填你的",
|
||||||
|
"remark" => "访问域名",
|
||||||
|
"sort" => 0,
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
"name" => "file",
|
"name" => "file",
|
||||||
"group" => "site",
|
"group" => "site",
|
||||||
|
|||||||
@@ -24,7 +24,13 @@
|
|||||||
<tip>设置允许上传大小。</tip>
|
<tip>设置允许上传大小。</tip>
|
||||||
</div>
|
</div>
|
||||||
</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">
|
<div class="layui-form-item show-type-item alioss">
|
||||||
<label class="layui-form-label required">公钥信息</label>
|
<label class="layui-form-label required">公钥信息</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
namespace app\common\service;
|
namespace app\common\service;
|
||||||
|
|
||||||
use app\admin\model\SystemUploadfile;
|
use app\admin\model\SystemUploadfile;
|
||||||
|
use app\common\tools\PathTools;
|
||||||
|
use think\facade\App;
|
||||||
use think\facade\Filesystem;
|
use think\facade\Filesystem;
|
||||||
use think\facade\Validate;
|
use think\facade\Validate;
|
||||||
use think\File;
|
use think\File;
|
||||||
@@ -129,4 +131,25 @@ class UploadService
|
|||||||
}
|
}
|
||||||
return $model_file;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,21 +14,21 @@ return [
|
|||||||
],
|
],
|
||||||
'local_public' => [
|
'local_public' => [
|
||||||
// 磁盘类型
|
// 磁盘类型
|
||||||
'type' => 'local',
|
'type' => 'LocalPublic',
|
||||||
// 磁盘路径
|
// 磁盘路径
|
||||||
'root' => app()->getRootPath() . 'public/storage',
|
'root' => app()->getRootPath() . 'public/storage',
|
||||||
// 磁盘路径对应的外部URL路径
|
// 磁盘路径对应的外部URL路径
|
||||||
'url' => Request::domain() . '/storage',
|
'url' => '/storage',
|
||||||
// 可见性
|
// 可见性
|
||||||
'visibility' => 'public',
|
'visibility' => 'public',
|
||||||
],
|
],
|
||||||
'local_static' => [
|
'local_static' => [
|
||||||
// 磁盘类型
|
// 磁盘类型
|
||||||
'type' => 'local',
|
'type' => 'LocalPublic',
|
||||||
// 磁盘路径
|
// 磁盘路径
|
||||||
'root' => app()->getRootPath() . 'public/static',
|
'root' => app()->getRootPath() . 'public/static',
|
||||||
// 磁盘路径对应的外部URL路径
|
// 磁盘路径对应的外部URL路径
|
||||||
'url' => Request::domain() . '/static',
|
'url' => '/static',
|
||||||
// 可见性
|
// 可见性
|
||||||
'visibility' => 'public',
|
'visibility' => 'public',
|
||||||
],
|
],
|
||||||
|
|||||||
30
extend/think/filesystem/driver/LocalPublic.php
Normal file
30
extend/think/filesystem/driver/LocalPublic.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user