mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
[更新]修复文件上传引擎选用问题
This commit is contained in:
parent
d88526bd8f
commit
e7cb857b76
@ -58,7 +58,7 @@ class Config extends BasicAdmin {
|
||||
*/
|
||||
public function file() {
|
||||
$alert = [
|
||||
'type' => 'info',
|
||||
'type' => 'success',
|
||||
'title' => '操作提示',
|
||||
'content' => '文件引擎参数影响全局文件上传功能,请勿随意修改!'
|
||||
];
|
||||
|
@ -85,14 +85,14 @@ class Plugs extends BasicAdmin {
|
||||
$this->result(['site_url' => $site_url], 'IS_FOUND');
|
||||
}
|
||||
// 需要上传文件,生成上传配置参数
|
||||
$config = ['uptype' => $post['uptype'], 'file_url' => $filename, 'server' => url('admin/plugs/upload')];
|
||||
$config = ['uptype' => $post['uptype'], 'file_url' => $filename];
|
||||
switch (strtolower($post['uptype'])) {
|
||||
case 'qiniu':
|
||||
$config['server'] = sysconf('storage_qiniu_is_https') ? 'https://up.qbox.me' : 'http://upload.qiniu.com';
|
||||
$config['server'] = FileService::getUploadQiniuUrl(true);
|
||||
$config['token'] = $this->_getQiniuToken($filename);
|
||||
break;
|
||||
case 'local':
|
||||
$config['server'] = url('admin/plugs/upload');
|
||||
$config['server'] = FileService::getUploadLocalUrl();
|
||||
break;
|
||||
}
|
||||
$this->result($config, 'NOT_FOUND');
|
||||
|
@ -1,97 +1,134 @@
|
||||
{extend name="extra@admin/content"}
|
||||
|
||||
{block name="content"}
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<form class=" layui-form" data-auto="" method="post">
|
||||
<fieldset class="layui-elem-field layui-box">
|
||||
<legend>文件存储</legend>
|
||||
<div class="layui-field-box" style="padding-right:35px">
|
||||
<form onsubmit="return false;" action="{$_url_}" data-auto="true" method="post"
|
||||
class='form-horizontal' style='padding-top:20px'>
|
||||
|
||||
<div class="layui-form-item layui-box">
|
||||
<label class="layui-form-label">Storage</label>
|
||||
<div class="layui-input-block">
|
||||
<select name="storage_type" lay-filter="storage_type" required="required">
|
||||
<option {if sysconf('storage_type')!=='qiniu'}selected{/if} value='local'>本地服务器</option>
|
||||
<option {if sysconf('storage_type')==='qiniu'}selected{/if} value='qiniu'>七牛云存储</option>
|
||||
</select>
|
||||
<div data-storage-type="qiniu" class="layui-form-mid layui-word-aux">
|
||||
若还没有帐号,请点击<a target="_blank" href="https://portal.qiniu.com/signup?code=3lhz6nmnwbple">免费申请10G存储空间</a>,申请成功后添加公开bucket空间!
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item layui-box" data-storage-type="qiniu">
|
||||
<label class="layui-form-label">https</label>
|
||||
<div class="layui-input-inline" style='width:50px'>
|
||||
<input type="hidden" name="storage_qiniu_is_https" value="0">
|
||||
{if sysconf('storage_qiniu_is_https')==1}
|
||||
<input type="checkbox" name="storage_qiniu_is_https" lay-skin="switch" checked required="required" title="https" value="1">
|
||||
{else/}
|
||||
<input type="checkbox" name="storage_qiniu_is_https" lay-skin="switch" required="required" title="https" value="1">
|
||||
{/if}
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux">是否启用https访问资源!</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item layui-box" data-storage-type="qiniu">
|
||||
<label class="layui-form-label">bucket</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="storage_qiniu_bucket" required="required" title="请输入七牛云 Bucket" placeholder="请输入七牛云 Bucket" value="{:sysconf('storage_qiniu_bucket')}" class="layui-input">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux">填写七牛云bucket名称,如:static</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item layui-box" data-storage-type="qiniu">
|
||||
<label class="layui-form-label">domain</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="storage_qiniu_domain" required="required" title="请输入七牛云 Domain" placeholder="请输入七牛云 Domain" value="{:sysconf('storage_qiniu_domain')}" class="layui-input">
|
||||
<div class="layui-form-mid layui-word-aux">只需填写域名,如:static.cdn.cuci.cc</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item layui-box" data-storage-type="qiniu">
|
||||
<label class="layui-form-label">access key</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="storage_qiniu_access_key" required="required" title="请输入七牛云 AccessKey" placeholder="请输入七牛云 AccessKey" value="{:sysconf('storage_qiniu_access_key')}" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item layui-box" data-storage-type="qiniu">
|
||||
<label class="layui-form-label">secret key</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="password" name="storage_qiniu_secret_key" required="required" title="请输入七牛云 SecretKey" placeholder="请输入七牛云 SecretKey" value="{:sysconf('storage_qiniu_secret_key')}" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="layui-form-item layui-box text-center">
|
||||
<button class="layui-btn" type="submit">立即提交</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">Storage <span class="nowrap">(存储引擎)</span></label>
|
||||
<div class='col-sm-8'>
|
||||
<select class="layui-input" name="storage_type" required="required">
|
||||
{if sysconf('storage_type')!=='qiniu'}
|
||||
<option selected value='local'>本地服务器</option>
|
||||
<option value='qiniu'>七牛云存储</option>
|
||||
{else/}
|
||||
<option value='local'>本地服务器</option>
|
||||
<option selected value='qiniu'>七牛云存储</option>
|
||||
{/if}
|
||||
</select>
|
||||
<div class="help-block" data-storage-type="qiniu">
|
||||
若还没有七牛云帐号,请点击
|
||||
<a target="_blank" href="https://portal.qiniu.com/signup?code=3lhz6nmnwbple">免费申请10G存储空间</a>,
|
||||
申请成功后添加公开bucket空间
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed" data-storage-type="qiniu"></div>
|
||||
|
||||
<div class="form-group" data-storage-type="qiniu">
|
||||
<label class="col-sm-2 control-label">Region <span class="nowrap">(存储区域)</span></label>
|
||||
<div class='col-sm-8'>
|
||||
<select class="layui-input" name="storage_qiniu_region" required="required">
|
||||
{if sysconf('storage_qiniu_region') eq '华东' }
|
||||
<option selected value='华东'>华东</option>
|
||||
{else/}
|
||||
<option value='华东'>华东</option>
|
||||
{/if}
|
||||
{if sysconf('storage_qiniu_region') eq '华北' }
|
||||
<option selected value='华北'>华北</option>
|
||||
{else/}
|
||||
<option value='华北'>华北</option>
|
||||
{/if}
|
||||
{if sysconf('storage_qiniu_region') eq '华南' }
|
||||
<option selected value='华南'>华南</option>
|
||||
{else/}
|
||||
<option value='华南'>华南</option>
|
||||
{/if}
|
||||
{if sysconf('storage_qiniu_region') eq '北美' }
|
||||
<option selected value='北美'>北美</option>
|
||||
{else/}
|
||||
<option value='北美'>北美</option>
|
||||
{/if}
|
||||
</select>
|
||||
<p class="help-block">七牛云存储空间所在域名,需要严格对应储存所在区域,否则无法上传文件。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" data-storage-type="qiniu">
|
||||
<label class="col-sm-2 control-label">Protocol <span class="nowrap">(访问协议)</span></label>
|
||||
<div class='col-sm-8'>
|
||||
<select class="layui-input" name="storage_qiniu_is_https" required="required">
|
||||
{if sysconf('storage_qiniu_is_https')!=='1'}
|
||||
<option selected value='0'>HTTP</option>
|
||||
<option value='1'>HTTPS</option>
|
||||
{else/}
|
||||
<option value='0'>HTTP</option>
|
||||
<option selected value='1'>HTTPS</option>
|
||||
{/if}
|
||||
</select>
|
||||
<p class="help-block">七牛云资源访问协议(http或https),https 需要单独配置证书</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group" data-storage-type="qiniu">
|
||||
<label class="col-sm-2 control-label">Bucket <span class="nowrap">(空间名称)</span></label>
|
||||
<div class='col-sm-8'>
|
||||
<input type="text" name="storage_qiniu_bucket" required="required" title="请输入七牛云存储 Bucket (空间名称)"
|
||||
placeholder="请输入七牛云存储 Bucket (空间名称)" value="{:sysconf('storage_qiniu_bucket')}"
|
||||
class="layui-input">
|
||||
<p class="help-block">填写七牛云存储空间名称,如:static</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" data-storage-type="qiniu">
|
||||
<label class="col-sm-2 control-label">Domain <span class="nowrap">(绑定域名)</span></label>
|
||||
<div class='col-sm-8'>
|
||||
<input type="text" name="storage_qiniu_domain" required="required" title="请输入七牛云存储 Domain (绑定域名)"
|
||||
placeholder="请输入七牛云存储 Domain (绑定域名)" value="{:sysconf('storage_qiniu_domain')}"
|
||||
class="layui-input">
|
||||
<p class="help-block">填写七牛云存储绑定域名,如:static.cdn.cuci.cc</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" data-storage-type="qiniu">
|
||||
<label class="col-sm-2 control-label">AccessKey <span class="nowrap">(访问密钥)</span></label>
|
||||
<div class='col-sm-8'>
|
||||
<input type="text" name="storage_qiniu_access_key" required="required" title="请输入七牛云 AccessKey (访问密钥)"
|
||||
placeholder="请输入七牛云 AccessKey (访问密钥)" value="{:sysconf('storage_qiniu_access_key')}"
|
||||
class="layui-input">
|
||||
<p class="help-block">可以在 七牛云 个人中心 设置并获取到访问密钥</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group" data-storage-type="qiniu">
|
||||
<label class="col-sm-2 control-label">SecretKey <span class="nowrap">(安全密钥)</span></label>
|
||||
<div class='col-sm-8'>
|
||||
<input type="text" name="storage_qiniu_secret_key" required="required" title="请输入七牛云 SecretKey (安全密钥)"
|
||||
placeholder="请输入七牛云 SecretKey (安全密钥)" value="{:sysconf('storage_qiniu_secret_key')}"
|
||||
maxlength="43" class="layui-input">
|
||||
<p class="help-block">可以在 七牛云 个人中心 设置并获取到安全密钥</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
|
||||
<div class="col-sm-4 col-sm-offset-2">
|
||||
<div class="layui-form-item text-center">
|
||||
<button class="layui-btn" type="submit">保存配置</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{/block}
|
||||
|
||||
{block name="script"}
|
||||
<script>
|
||||
|
||||
$(function () {
|
||||
// 默认初始化布局
|
||||
initLayout($('[name="storage_type"]').val());
|
||||
// 表单动态渲染
|
||||
window.form.render();
|
||||
/*! 兼听 select 的值变化 */
|
||||
window.form.on('select(storage_type)', function (data) {
|
||||
// 重新初始化布局
|
||||
initLayout(data.value);
|
||||
});
|
||||
// 表单初始化布局
|
||||
function initLayout(storage_type) {
|
||||
$("[data-storage-type]").not($("[data-storage-type='" + storage_type + "']").show()).hide();
|
||||
}
|
||||
$('[name="storage_type"]').on('change', function () {
|
||||
$("[data-storage-type]").not($("[data-storage-type='" + $(this).val() + "']").show()).hide();
|
||||
}).trigger('change');
|
||||
});
|
||||
</script>
|
||||
{/block}
|
@ -67,6 +67,47 @@ class FileService {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据配置获取到七牛云文件上传目标地址
|
||||
* @return string
|
||||
*/
|
||||
public static function getUploadLocalUrl() {
|
||||
return url('@admin/plugs/upload');
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据配置获取到七牛云文件上传目标地址
|
||||
* @param bool $isClient
|
||||
* @return string
|
||||
*/
|
||||
public static function getUploadQiniuUrl($isClient = true) {
|
||||
$region = sysconf('storage_qiniu_region');
|
||||
$isHttps = !!sysconf('storage_qiniu_is_https');
|
||||
switch ($region) {
|
||||
case '华东':
|
||||
if ($isHttps) {
|
||||
return $isClient ? 'https://upload.qbox.me' : 'https://up.qbox.me';
|
||||
}
|
||||
return $isClient ? 'http://upload.qiniu.com' : 'http://up.qiniu.com';
|
||||
case '华北':
|
||||
if ($isHttps) {
|
||||
return $isClient ? 'https://upload-z1.qbox.me' : 'https://up-z1.qbox.me';
|
||||
}
|
||||
return $isClient ? 'http://upload-z1.qiniu.com' : 'http://up-z1.qiniu.com';
|
||||
case '北美':
|
||||
if ($isHttps) {
|
||||
return $isClient ? 'https://upload-na0.qbox.me' : 'https://up-na0.qbox.me';
|
||||
}
|
||||
return $isClient ? 'http://upload-na0.qiniu.com' : 'http://up-na0.qiniu.com';
|
||||
case '华南':
|
||||
default:
|
||||
if ($isHttps) {
|
||||
return $isClient ? 'https://upload-z2.qbox.me' : 'https://up-z2.qbox.me';
|
||||
}
|
||||
return $isClient ? 'http://upload-z2.qiniu.com' : 'http://up-z2.qiniu.com';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务器URL前缀
|
||||
* @return string
|
||||
|
Loading…
x
Reference in New Issue
Block a user