切换导航条
此项目
正在载入...
登录
李忠强
/
temporaryfood
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
李忠强
3 years ago
提交
a6f9b3ae30de0145a6bfbeefd81e089fbd82409e
1 个父辈
59c98c47
更新
隐藏空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
31 行增加
和
2 行删除
application/common/library/Upload.php
thinkphp/base.php
application/common/library/Upload.php
查看文件 @
a6f9b3a
...
...
@@ -6,6 +6,8 @@ use app\common\exception\UploadException;
use
app\common\model\Attachment
;
use
fast\Random
;
use
FilesystemIterator
;
use
Qiniu\Auth
;
use
Qiniu\Storage\UploadManager
;
use
think\Config
;
use
think\File
;
use
think\Hook
;
...
...
@@ -358,7 +360,7 @@ class Upload
$this
->
file
=
$file
;
$category
=
request
()
->
post
(
'category'
);
$category
=
array_key_exists
(
$category
,
config
(
'site.attachmentcategory'
)
??
[])
?
$category
:
''
;
$auth
=
Auth
::
instance
();
$auth
=
\app\common\library\
Auth
::
instance
();
$params
=
array
(
'admin_id'
=>
(
int
)
session
(
'admin.id'
),
'user_id'
=>
(
int
)
$auth
->
id
,
...
...
@@ -376,6 +378,8 @@ class Upload
'sha1'
=>
$sha1
,
'extparam'
=>
''
,
);
$token
=
$this
->
getQiniuToken
();
$this
->
qiniu
(
PUBLIC_PATH
.
$params
[
'url'
],
$params
[
'url'
],
$token
);
$attachment
=
new
Attachment
();
$attachment
->
data
(
array_filter
(
$params
));
$attachment
->
save
();
...
...
@@ -384,6 +388,31 @@ class Upload
return
$attachment
;
}
/**
* @param $filename (文件路径)
* @param $key (文件名)
* @param $token (上传token)
* @return (null|jsonstring)
* @throws \Exception
*/
protected
function
qiniu
(
$filename
,
$key
,
$token
)
{
$upload
=
new
UploadManager
();
list
(
$ret
,
$err
)
=
$upload
->
putFile
(
$token
,
$key
,
$filename
);
return
$err
;
}
/**
* 获取七牛云上传token 一小时有效期
* @return string
*/
protected
function
getQiniuToken
()
{
$config
=
get_addon_config
(
'qiniu'
);
$auth
=
new
Auth
(
$config
[
'accessKey'
],
$config
[
'secretKey'
]);
$token
=
$auth
->
uploadToken
(
$config
[
'bucket'
]);
return
$token
;
}
public
function
setError
(
$msg
)
{
$this
->
error
=
$msg
;
...
...
thinkphp/base.php
查看文件 @
a6f9b3a
...
...
@@ -29,7 +29,7 @@ defined('TEMP_PATH') or define('TEMP_PATH', RUNTIME_PATH . 'temp' . DS);
defined
(
'CONF_PATH'
)
or
define
(
'CONF_PATH'
,
APP_PATH
);
// 配置文件目录
defined
(
'CONF_EXT'
)
or
define
(
'CONF_EXT'
,
EXT
);
// 配置文件后缀
defined
(
'ENV_PREFIX'
)
or
define
(
'ENV_PREFIX'
,
'PHP_'
);
// 环境变量的配置前缀
define
(
'PUBLIC_PATH'
,
ROOT_PATH
.
'public'
);
// 环境常量
define
(
'IS_CLI'
,
PHP_SAPI
==
'cli'
?
true
:
false
);
define
(
'IS_WIN'
,
strpos
(
PHP_OS
,
'WIN'
)
!==
false
);
...
...
请
注册
或
登录
后发表评论