切换导航条
此项目
正在载入...
登录
何书鹏
/
anttest
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
Karson
8 years ago
提交
41075e2d34770a9ab60d7f543b2e772183437a5d
1 个父辈
e3ea52ea
新增上传到本机时文件名规则和大小控制
修复无法编辑管理员的BUG 添加批量上传参数配置
隐藏空白字符变更
内嵌
并排对比
正在显示
4 个修改的文件
包含
69 行增加
和
15 行删除
application/admin/controller/Ajax.php
application/admin/controller/auth/Admin.php
application/common/model/Configvalue.php
public/assets/js/require-upload.js
application/admin/controller/Ajax.php
查看文件 @
41075e2
...
...
@@ -4,7 +4,9 @@ namespace app\admin\controller;
use
app\common\controller\Backend
;
use
fast\Http
;
use
fast\Random
;
use
fast\Tree
;
use
think\Config
;
use
think\Db
;
use
think\Lang
;
...
...
@@ -181,12 +183,58 @@ class Ajax extends Backend
{
$this->code
= -1;
$file
=
$this->request
->file('file');
$uploaddir
= '/public/uploads/';
$info
=
$file->move
(ROOT_PATH .
$uploaddir
);
if (
$info
)
$upload
= Config::get('upload');
preg_match('/(\d+)(\w+)/',
$upload['maxsize']
,
$matches
);
$type
= strtolower(
$matches[2]
);
$typeDict
= ['b' => 0, 'k' => 1, 'kb' => 1, 'm' => 2, 'mb' => 2, 'gb' => 3, 'g' => 3];
$size
= (int)
$upload['maxsize']
* pow(1024, isset(
$typeDict[$type]
) ?
$typeDict[$type]
: 0);
$fileInfo
=
$file->getInfo
();
$suffix
= strtolower(pathinfo(
$fileInfo['name']
, PATHINFO_EXTENSION));
$suffix
=
$suffix
?
$suffix
: 'file';
$replaceArr
= [
'
{
year
}
' => date("
Y
"),
'
{
mon
}
' => date("
m
"),
'
{
day
}
' => date("
d
"),
'
{
hour
}
' => date("
H
"),
'
{
min
}
' => date("
i
"),
'
{
sec
}
' => date("
s
"),
'
{
random
}
' => Random::alnum(16),
'
{
random32
}
' => Random::alnum(32),
'
{
filename
}
' =>
$suffix
? substr(
$fileInfo['name']
, 0, strripos(
$fileInfo['name']
, '.')) :
$fileInfo['name']
,
'
{
suffix
}
' =>
$suffix
,
'
{
.suffix
}
' =>
$suffix
? '.' .
$suffix
: '',
'
{
filemd5
}
' => md5_file(
$fileInfo['tmp_name']
),
];
$savekey
=
$upload['savekey']
;
$savekey
= str_replace(array_keys(
$replaceArr
), array_values(
$replaceArr
),
$savekey
);
$uploadDir
= substr(
$savekey
, 0, strripos(
$savekey
, '/') + 1);
$fileName
= substr(
$savekey
, strripos(
$savekey
, '/') + 1);
//
$splInfo
=
$file->validate
(['size' =>
$size
])->move(ROOT_PATH . '/public' .
$uploadDir
,
$fileName
);
if (
$splInfo
)
{
$imagewidth
=
$imageheight
= 0;
if (in_array(
$suffix
, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf']))
{
$imgInfo
= getimagesize(
$splInfo->getPathname
());
$imagewidth
= isset(
$imgInfo[0]
) ?
$imgInfo[0]
:
$imagewidth
;
$imageheight
= isset(
$imgInfo[1]
) ?
$imgInfo[1]
:
$imageheight
;
}
$params
= array(
'filesize' =>
$fileInfo['size']
,
'imagewidth' =>
$imagewidth
,
'imageheight' =>
$imageheight
,
'imagetype' =>
$suffix
,
'imageframes' => 0,
'mimetype' =>
$fileInfo['type']
,
'url' =>
$uploadDir
.
$splInfo->getSaveName
(),
'uploadtime' => time()
);
model("
attachment
")->create(array_filter(
$params
));
$this->code
= 200;
$this->data
=
$upload
dir
.
$i
nfo->getSaveName
();
$this->data
=
$upload
Dir
.
$splI
nfo->getSaveName
();
}
else
{
...
...
application/admin/controller/auth/Admin.php
查看文件 @
41075e2
...
...
@@ -96,7 +96,7 @@ class Admin extends Backend
{
if
(
$params
[
'password'
])
{
$params
[
'salt'
]
=
Random
::
basic
(
4
);
$params
[
'salt'
]
=
Random
::
alnum
(
);
$params
[
'password'
]
=
md5
(
md5
(
$params
[
'password'
])
.
$params
[
'salt'
]);
}
$row
->
save
(
$params
);
...
...
application/common/model/Configvalue.php
查看文件 @
41075e2
...
...
@@ -32,6 +32,7 @@ class Configvalue extends Model
$uploadcfg
=
$uploadcfg
?
$uploadcfg
:
[];
$uploadcfg
=
array_merge
(
$uploadcfg
,
$params
);
$uploadcfg
[
'bucket'
]
=
isset
(
$uploadcfg
[
'bucket'
])
?
$uploadcfg
[
'bucket'
]
:
''
;
$multiple
=
isset
(
$uploadcfg
[
'multiple'
])
?
$uploadcfg
[
'multiple'
]
:
false
;
$savekey
=
isset
(
$uploadcfg
[
'savekey'
])
?
$uploadcfg
[
'savekey'
]
:
''
;
$uploadcfg
[
'save-key'
]
=
isset
(
$uploadcfg
[
'save-key'
])
?
$uploadcfg
[
'save-key'
]
:
$savekey
;
$expiration
=
time
()
+
(
isset
(
$uploadcfg
[
'expire'
])
?
$uploadcfg
[
'expire'
]
:
600
);
...
...
@@ -68,6 +69,7 @@ class Configvalue extends Model
'maxsize'
=>
isset
(
$uploadcfg
[
'maxsize'
])
?
$uploadcfg
[
'maxsize'
]
:
''
,
'mimetype'
=>
isset
(
$uploadcfg
[
'mimetype'
])
?
$uploadcfg
[
'mimetype'
]
:
''
,
'multipart'
=>
$multipart
,
'multiple'
=>
$multiple
,
];
}
...
...
public/assets/js/require-upload.js
查看文件 @
41075e2
...
...
@@ -15,6 +15,7 @@ define(['jquery', 'bootstrap', 'backend', 'config', 'plupload'], function ($, un
var
maxsize
=
$
(
this
).
data
(
"maxsize"
);
var
mimetype
=
$
(
this
).
data
(
"mimetype"
);
var
multipart
=
$
(
this
).
data
(
"multipart"
);
var
multiple
=
$
(
this
).
data
(
"multiple"
);
//上传URL
url
=
url
?
url
:
Config
.
upload
.
uploadurl
;
//最大可上传
...
...
@@ -23,10 +24,13 @@ define(['jquery', 'bootstrap', 'backend', 'config', 'plupload'], function ($, un
mimetype
=
mimetype
?
mimetype
:
Config
.
upload
.
mimetype
;
//请求的表单参数
multipart
=
multipart
?
multipart
:
Config
.
upload
.
multipart
;
//是否支持批量上传
multiple
=
multiple
?
multiple
:
Config
.
upload
.
multiple
;
//生成Plupload实例
Upload
.
list
[
id
]
=
new
Plupload
.
Uploader
({
runtimes
:
'html5,flash,silverlight,html4'
,
multi_selection
:
false
,
//是否允许多选批量上传
browse_button
:
id
,
// you can pass an id...
multi_selection
:
multiple
,
//是否允许多选批量上传
browse_button
:
id
,
// 浏览按钮的ID
container
:
$
(
this
).
parent
().
get
(
0
),
//取按钮的上级元素
flash_swf_url
:
'/assets/libs/plupload/js/Moxie.swf'
,
silverlight_xap_url
:
'/assets/libs/plupload/js/Moxie.xap'
,
...
...
@@ -63,19 +67,19 @@ define(['jquery', 'bootstrap', 'backend', 'config', 'plupload'], function ($, un
//document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML += (' [Url]: ' + '<a href="' + url + '" target="_blank">' + url + '</a>');
//这里建议不修改
try
{
var
data
=
JSON
.
parse
(
info
.
response
);
if
(
data
.
hasOwnProperty
(
'code'
))
{
data
.
code
=
data
.
code
==
200
?
0
:
data
.
code
;
if
(
data
.
hasOwnProperty
(
"url"
))
{
data
.
content
=
data
.
url
;
var
response
=
JSON
.
parse
(
info
.
response
);
if
(
response
.
hasOwnProperty
(
'code'
))
{
response
.
code
=
response
.
code
==
200
?
1
:
response
.
code
;
if
(
response
.
hasOwnProperty
(
"url"
))
{
response
.
data
=
response
.
url
;
}
$
(
"input[data-plupload-id='"
+
id
+
"-text']"
).
val
(
data
.
content
);
$
(
"input[data-plupload-id='"
+
id
+
"-text']"
).
val
(
response
.
data
);
var
afterUpload
=
$
(
"#"
+
id
).
data
(
"after-upload"
);
if
(
afterUpload
&&
typeof
Upload
.
api
.
custom
[
afterUpload
]
==
'function'
)
{
Upload
.
api
.
custom
[
afterUpload
].
call
(
info
,
id
,
data
);
Upload
.
api
.
custom
[
afterUpload
].
call
(
info
,
id
,
response
);
}
if
(
typeof
onAfterUpload
==
'function'
)
{
onAfterUpload
.
call
(
info
,
id
,
data
);
onAfterUpload
.
call
(
info
,
id
,
response
);
}
}
else
{
Toastr
.
error
(
e
.
message
+
"(code:-2)"
);
...
...
请
注册
或
登录
后发表评论