切换导航条
此项目
正在载入...
登录
何书鹏
/
recruit
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
Karson
7 years ago
提交
5a87939e860736da4433e4d2b9f1c54445f7ee77
1 个父辈
3a92ef55
修复本地上传未限制文件格式的BUG
隐藏空白字符变更
内嵌
并排对比
正在显示
4 个修改的文件
包含
43 行增加
和
11 行删除
application/admin/controller/Ajax.php
application/admin/lang/zh-cn/ajax.php
application/index/controller/Ajax.php
application/index/lang/zh-cn/ajax.php
application/admin/controller/Ajax.php
查看文件 @
5a87939
...
...
@@ -49,7 +49,7 @@ class Ajax extends Backend
$file
=
$this
->
request
->
file
(
'file'
);
if
(
empty
(
$file
))
{
$this
->
error
(
"未上传文件或超出服务器上传限制"
);
$this
->
error
(
__
(
'No file upload or server upload limit exceeded'
)
);
}
//判断是否已经存在附件
...
...
@@ -64,6 +64,14 @@ class Ajax extends Backend
$fileInfo
=
$file
->
getInfo
();
$suffix
=
strtolower
(
pathinfo
(
$fileInfo
[
'name'
],
PATHINFO_EXTENSION
));
$suffix
=
$suffix
?
$suffix
:
'file'
;
$mimetypeArr
=
explode
(
','
,
$upload
[
'mimetype'
]);
$typeArr
=
explode
(
'/'
,
$fileInfo
[
'type'
]);
//验证文件后缀
if
(
$upload
[
'mimetype'
]
!==
'*'
&&
!
in_array
(
$suffix
,
$mimetypeArr
)
&&
!
in_array
(
$fileInfo
[
'type'
],
$mimetypeArr
)
&&
!
in_array
(
$typeArr
[
0
]
.
'/*'
,
$mimetypeArr
))
{
$this
->
error
(
__
(
'Uploaded file format is limited'
));
}
$replaceArr
=
[
'{year}'
=>
date
(
"Y"
),
'{mon}'
=>
date
(
"m"
),
...
...
@@ -110,7 +118,7 @@ class Ajax extends Backend
$attachment
->
data
(
array_filter
(
$params
));
$attachment
->
save
();
\think\Hook
::
listen
(
"upload_after"
,
$attachment
);
$this
->
success
(
'上传成功'
,
null
,
[
$this
->
success
(
__
(
'Upload successful'
)
,
null
,
[
'url'
=>
$uploadDir
.
$splInfo
->
getSaveName
()
]);
}
...
...
application/admin/lang/zh-cn/ajax.php
0 → 100644
查看文件 @
5a87939
<?php
return
[
'No file upload or server upload limit exceeded'
=>
'未上传文件或超出服务器上传限制'
,
'Uploaded file format is limited'
=>
'上传文件格式受限制'
,
'Upload successful'
=>
'上传成功'
,
];
...
...
application/index/controller/Ajax.php
查看文件 @
5a87939
...
...
@@ -37,17 +37,15 @@ class Ajax extends Frontend
*/
public
function
upload
()
{
Config
::
set
(
'default_return_type'
,
'json'
);
$file
=
$this
->
request
->
file
(
'file'
);
if
(
empty
(
$file
))
{
$this
->
error
(
__
(
'No file upload or server upload limit exceeded'
));
}
//判断是否已经存在附件
$sha1
=
$file
->
hash
();
$uploaded
=
model
(
"attachment"
)
->
where
(
'sha1'
,
$sha1
)
->
find
();
if
(
$uploaded
)
{
$this
->
success
(
''
,
null
,
[
'url'
=>
$uploaded
[
'url'
]
]);
}
$upload
=
Config
::
get
(
'upload'
);
...
...
@@ -58,6 +56,14 @@ class Ajax extends Frontend
$fileInfo
=
$file
->
getInfo
();
$suffix
=
strtolower
(
pathinfo
(
$fileInfo
[
'name'
],
PATHINFO_EXTENSION
));
$suffix
=
$suffix
?
$suffix
:
'file'
;
$mimetypeArr
=
explode
(
','
,
$upload
[
'mimetype'
]);
$typeArr
=
explode
(
'/'
,
$fileInfo
[
'type'
]);
//验证文件后缀
if
(
$upload
[
'mimetype'
]
!==
'*'
&&
!
in_array
(
$suffix
,
$mimetypeArr
)
&&
!
in_array
(
$fileInfo
[
'type'
],
$mimetypeArr
)
&&
!
in_array
(
$typeArr
[
0
]
.
'/*'
,
$mimetypeArr
))
{
$this
->
error
(
__
(
'Uploaded file format is limited'
));
}
$replaceArr
=
[
'{year}'
=>
date
(
"Y"
),
'{mon}'
=>
date
(
"m"
),
...
...
@@ -97,10 +103,14 @@ class Ajax extends Frontend
'mimetype'
=>
$fileInfo
[
'type'
],
'url'
=>
$uploadDir
.
$splInfo
->
getSaveName
(),
'uploadtime'
=>
time
(),
'storage'
=>
'local'
,
'sha1'
=>
$sha1
,
);
model
(
"attachment"
)
->
create
(
array_filter
(
$params
));
$this
->
success
(
''
,
null
,
[
$attachment
=
model
(
"attachment"
);
$attachment
->
data
(
array_filter
(
$params
));
$attachment
->
save
();
\think\Hook
::
listen
(
"upload_after"
,
$attachment
);
$this
->
success
(
__
(
'Upload successful'
),
null
,
[
'url'
=>
$uploadDir
.
$splInfo
->
getSaveName
()
]);
}
...
...
application/index/lang/zh-cn/ajax.php
0 → 100644
查看文件 @
5a87939
<?php
return
[
'No file upload or server upload limit exceeded'
=>
'未上传文件或超出服务器上传限制'
,
'Uploaded file format is limited'
=>
'上传文件格式受限制'
,
'Upload successful'
=>
'上传成功'
,
];
...
...
请
注册
或
登录
后发表评论