Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
starsw001
ShopXO
提交
d4d93c2c
ShopXO
项目概览
starsw001
/
ShopXO
与 Fork 源项目一致
Fork自
纵之格 / ShopXO
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
ShopXO
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d4d93c2c
编写于
2月 26, 2019
作者:
D
devil_gong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
上传文件优化
上级
47e1b682
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
120 addition
and
18 deletion
+120
-18
application/admin/config/app.php
application/admin/config/app.php
+3
-0
application/admin/controller/Ueditor.php
application/admin/controller/Ueditor.php
+6
-3
extend/base/Uploader.php
extend/base/Uploader.php
+111
-15
未找到文件。
application/admin/config/app.php
浏览文件 @
d4d93c2c
...
...
@@ -75,6 +75,9 @@ return [
// 上传大小限制,单位B
'scrawlMaxSize'
=>
MyC
(
'home_max_limit_image'
,
2048000
,
true
),
// 上传图片格式显示
'scrawlAllowFiles'
=>
[
'.png'
,
'.jpg'
,
'.jpeg'
,
'.gif'
,
'.bmp'
],
// 图片访问路径前缀
'scrawlUrlPrefix'
=>
''
,
...
...
application/admin/controller/Ueditor.php
浏览文件 @
d4d93c2c
...
...
@@ -171,7 +171,7 @@ class Ueditor extends Common
*/
private
function
ActionUpload
()
{
$
base64
=
"upload
"
;
$
type
=
"file
"
;
switch
(
htmlspecialchars
(
$this
->
current_action
))
{
case
'uploadimage'
:
...
...
@@ -181,6 +181,7 @@ class Ueditor extends Common
"allowFiles"
=>
$this
->
current_config
[
'imageAllowFiles'
]
);
$field_name
=
$this
->
current_config
[
'imageFieldName'
];
$type
=
"image"
;
break
;
case
'uploadscrawl'
:
...
...
@@ -191,7 +192,7 @@ class Ueditor extends Common
"oriName"
=>
"scrawl.png"
);
$field_name
=
$this
->
current_config
[
'scrawlFieldName'
];
$
base64
=
"base64"
;
$
type
=
"base64"
;
break
;
case
'uploadvideo'
:
...
...
@@ -201,6 +202,7 @@ class Ueditor extends Common
"allowFiles"
=>
$this
->
current_config
[
'videoAllowFiles'
]
);
$field_name
=
$this
->
current_config
[
'videoFieldName'
];
$type
=
"video"
;
break
;
case
'uploadfile'
:
...
...
@@ -211,10 +213,11 @@ class Ueditor extends Common
"allowFiles"
=>
$this
->
current_config
[
'fileAllowFiles'
]
);
$field_name
=
$this
->
current_config
[
'fileFieldName'
];
$type
=
"file"
;
}
/* 生成上传实例对象并完成上传 */
$up
=
new
\
base\Uploader
(
$field_name
,
$temp_config
,
$
base64
);
$up
=
new
\
base\Uploader
(
$field_name
,
$temp_config
,
$
type
);
/**
* 得到上传文件所对应的各个参数,数组结构
...
...
extend/base/Uploader.php
浏览文件 @
d4d93c2c
...
...
@@ -43,7 +43,7 @@ class Uploader
"ERROR_TYPE_NOT_ALLOWED"
=>
"文件类型不允许"
,
"ERROR_CREATE_DIR"
=>
"目录创建失败"
,
"ERROR_DIR_NOT_WRITEABLE"
=>
"目录没有写权限"
,
"ERROR_FILE_MOVE"
=>
"保存出错,
图片
有误"
,
"ERROR_FILE_MOVE"
=>
"保存出错,
文件
有误"
,
"ERROR_FILE_NOT_FOUND"
=>
"找不到上传文件"
,
"ERROR_WRITE_CONTENT"
=>
"写入文件内容错误"
,
"ERROR_UNKNOWN"
=>
"未知错误"
,
...
...
@@ -52,6 +52,8 @@ class Uploader
"ERROR_HTTP_CONTENTTYPE"
=>
"链接contentType不正确"
,
"INVALID_URL"
=>
"非法 URL"
,
"INVALID_IP"
=>
"非法 IP"
,
"ERROR_IMAGE_SAVE"
=>
"保存出错,图片有误"
,
"ERROR_UPLOAD_TYPE"
=>
"操作类型有误"
,
);
/**
...
...
@@ -65,21 +67,107 @@ class Uploader
$this
->
fileField
=
$fileField
;
$this
->
config
=
$config
;
$this
->
type
=
$type
;
if
(
$type
==
"remote"
)
{
$this
->
saveRemote
();
}
else
if
(
$type
==
"base64"
)
{
$this
->
upBase64
();
}
else
{
$this
->
upFile
();
switch
(
$this
->
type
)
{
// 抓取远程文件
case
'remote'
:
$this
->
saveRemote
();
break
;
// base64文件
case
'base64'
:
$this
->
uploadBase64
();
break
;
// 图片
case
'image'
:
$this
->
uploadImage
();
break
;
// 文件、视频
case
'file'
:
case
'video'
:
$this
->
uploadFile
();
break
;
// 默认
default
:
$this
->
stateInfo
=
$this
->
getStateInfo
(
"ERROR_UPLOAD_TYPE"
);
}
}
/**
* 文件上传
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-02-26
* @desc description
*/
private
function
uploadFile
()
{
$file
=
$this
->
file
=
$_FILES
[
$this
->
fileField
];
if
(
!
$file
)
{
$this
->
stateInfo
=
$this
->
getStateInfo
(
"ERROR_FILE_NOT_FOUND"
);
return
;
}
if
(
$this
->
file
[
'error'
])
{
$this
->
stateInfo
=
$this
->
getStateInfo
(
$file
[
'error'
]);
return
;
}
else
if
(
!
file_exists
(
$file
[
'tmp_name'
]))
{
$this
->
stateInfo
=
$this
->
getStateInfo
(
"ERROR_TMP_FILE_NOT_FOUND"
);
return
;
}
else
if
(
!
is_uploaded_file
(
$file
[
'tmp_name'
]))
{
$this
->
stateInfo
=
$this
->
getStateInfo
(
"ERROR_TMPFILE"
);
return
;
}
$this
->
oriName
=
$file
[
'name'
];
$this
->
fileSize
=
$file
[
'size'
];
$this
->
fileType
=
$this
->
getFileExt
();
$this
->
fullName
=
$this
->
getFullName
();
$this
->
filePath
=
$this
->
getFilePath
();
$this
->
fileName
=
$this
->
getFileName
();
$dirname
=
dirname
(
$this
->
filePath
);
//检查文件大小是否超出限制
if
(
!
$this
->
checkSize
())
{
$this
->
stateInfo
=
$this
->
getStateInfo
(
"ERROR_SIZE_EXCEED"
);
return
;
}
//检查是否不允许的文件格式
if
(
!
$this
->
checkType
())
{
$this
->
stateInfo
=
$this
->
getStateInfo
(
"ERROR_TYPE_NOT_ALLOWED"
);
return
;
}
//创建目录失败
if
(
!
is_dir
(
$dirname
)
&&
!@
mkdir
(
$dirname
,
0777
,
true
))
{
$this
->
stateInfo
=
$this
->
getStateInfo
(
"ERROR_CREATE_DIR"
);
return
;
}
else
if
(
!
is_writeable
(
$dirname
))
{
$this
->
stateInfo
=
$this
->
getStateInfo
(
"ERROR_DIR_NOT_WRITEABLE"
);
return
;
}
//移动文件
if
(
!
(
move_uploaded_file
(
$file
[
"tmp_name"
],
$this
->
filePath
)
&&
file_exists
(
$this
->
filePath
)))
{
//移动失败
$this
->
stateInfo
=
$this
->
getStateInfo
(
"ERROR_FILE_MOVE"
);
}
else
{
//移动成功
$this
->
stateInfo
=
$this
->
stateMap
[
0
];
}
//$this->stateMap['ERROR_TYPE_NOT_ALLOWED'] = iconv('unicode', 'utf-8', $this->stateMap['ERROR_TYPE_NOT_ALLOWED']);
}
/**
* 上传文件的主处理方法
* @return mixed
* 图片上传
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-02-26
* @desc description
*/
private
function
up
Fil
e
()
private
function
up
loadImag
e
()
{
$file
=
$this
->
file
=
$_FILES
[
$this
->
fileField
];
if
(
!
$file
)
{
...
...
@@ -150,7 +238,7 @@ class Uploader
}
if
(
!
file_exists
(
$this
->
filePath
))
{
$this
->
stateInfo
=
$this
->
getStateInfo
(
"ERROR_
FILE_MO
VE"
);
$this
->
stateInfo
=
$this
->
getStateInfo
(
"ERROR_
IMAGE_SA
VE"
);
}
else
{
$this
->
stateInfo
=
$this
->
stateMap
[
0
];
}
...
...
@@ -158,9 +246,13 @@ class Uploader
/**
* 处理base64编码的图片上传
* @return mixed
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-02-26
* @desc description
*/
private
function
upBase64
()
private
function
up
load
Base64
()
{
$base64Data
=
$_POST
[
$this
->
fileField
];
$img
=
base64_decode
(
$base64Data
);
...
...
@@ -199,7 +291,11 @@ class Uploader
/**
* 拉取远程图片
* @return mixed
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-02-26
* @desc description
*/
private
function
saveRemote
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录