开始实现使用内部的上传逻辑;

This commit is contained in:
2022-07-11 17:41:20 +08:00
parent 5081cd8790
commit 3078dfad39
12 changed files with 396 additions and 777 deletions

View File

@@ -6,9 +6,11 @@ namespace app\admin\controller;
use app\admin\model\SystemUploadfile;
use app\common\controller\AdminController;
use app\common\service\MenuService;
use app\common\service\UploadService;
use EasyAdmin\upload\Uploadfile;
use think\db\Query;
use think\facade\Cache;
use think\facade\Filesystem;
class Ajax extends AdminController
{
@@ -59,27 +61,20 @@ class Ajax extends AdminController
'upload_type' => $this->request->post('upload_type'),
'file' => $this->request->file('file'),
];
$uploadConfig = sysconfig('upload');
empty($data['upload_type']) && $data['upload_type'] = $uploadConfig['upload_type'];
$rule = [
'upload_type|指定上传类型有误' => "in:{$uploadConfig['upload_allow_type']}",
'file|文件' => "require|file|fileExt:{$uploadConfig['upload_allow_ext']}|fileSize:{$uploadConfig['upload_allow_size']}",
];
$this->validate($data, $rule);
try {
$upload = Uploadfile::instance()
->setUploadType($data['upload_type'])
->setUploadConfig($uploadConfig)
->setFile($data['file'])
->save();
$upload_service = new UploadService($data['upload_type']);
$upload_service->validateException($data['file']);
$result = $upload_service->save($data['file']);
} catch (\Exception $e) {
$this->error($e->getMessage());
}
if ($upload['save'] == true) {
$this->success($upload['msg'], ['url' => $upload['url']]);
} else {
$this->error($upload['msg']);
}
$this->success('上传成功', $result);
}
/**
@@ -158,5 +153,4 @@ class Ajax extends AdminController
];
return json($data);
}
}
}