修改文件上传,后缀带原文件名

This commit is contained in:
Anyon 2020-01-13 16:07:48 +08:00
parent 8508aa5693
commit 592142cc87
3 changed files with 9 additions and 8 deletions

View File

@ -56,9 +56,10 @@ class Upload extends Controller
*/
public function state()
{
$this->name = input('name', null);
$this->safe = boolval(input('safe'));
$data = ['uptype' => $this->getType(), 'xkey' => input('xkey')];
if ($info = Storage::instance($data['uptype'])->info($data['xkey'], $this->safe)) {
if ($info = Storage::instance($data['uptype'])->info($data['xkey'], $this->safe, $this->name)) {
$data['url'] = $info['url'];
$this->success('文件已经上传', $data, 200);
} elseif ('local' === $data['uptype']) {
@ -66,7 +67,7 @@ class Upload extends Controller
$data['server'] = LocalStorage::instance()->upload();
} elseif ('qiniu' === $data['uptype']) {
$data['url'] = QiniuStorage::instance()->url($data['xkey']);
$data['token'] = QiniuStorage::instance()->buildUploadToken($data['xkey']);
$data['token'] = QiniuStorage::instance()->buildUploadToken($data['xkey'], 3600, $this->name);
$data['server'] = QiniuStorage::instance()->upload();
} elseif ('alioss' === $data['uptype']) {
$token = AliossStorage::instance()->buildUploadToken($data['xkey']);

View File

@ -23,12 +23,12 @@ define(['md5'], function (SparkMD5, allowExtsMimes) {
idx: 0, auto: false, headers: headers || {}, multiple: opt.multiple,
accept: 'file', elem: element, exts: options.exts, acceptMime: options.acceptMime,
choose: function (object, files) {
files = object.pushFile(), opt.input.data('files', files), opt.element.data('files', files);
files = object.pushFile(), opt.element.data('files', files);
for (index in files) md5file(files[index]).then(function (file) {
opt.input.data('file', file).data('index', index), opt.element.data('file', file).data('index', index);
opt.element.data('file', file).data('index', index);
jQuery.ajax("{:url('@admin/api.upload/state')}", {
data: {xkey: file.xkey, uptype: opt.uptype, safe: opt.safe}, method: 'post', success: function (ret) {
file.xurl = ret.data.url + '?attname=' + encodeURIComponent(file.name);
data: {xkey: file.xkey, uptype: opt.uptype, safe: opt.safe, name: file.name}, method: 'post', success: function (ret) {
file.xurl = ret.data.url + (ret.data.url.indexOf('?attname=') > -1 ? '' : '?attname=' + encodeURIComponent(file.name));
if (parseInt(ret.code) === 404) {
uploader.config.url = ret.data.server;
uploader.config.data.key = ret.data.xkey;
@ -45,7 +45,7 @@ define(['md5'], function (SparkMD5, allowExtsMimes) {
}
object.upload(index, file);
} else if (parseInt(ret.code) === 200) {
UploadedHandler.call(opt.element, ret.data.url, file);
UploadedHandler.call(opt.element, file.xurl, file);
} else {
$.msg.error(ret.info || ret.error.message || '文件上传出错!');
}

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php
// This file is automatically generated at:2020-01-13 15:51:21
// This file is automatically generated at:2020-01-13 16:07:29
declare (strict_types = 1);
return array (
0 => 'think\\app\\Service',