This commit is contained in:
molong
2022-10-18 21:09:17 +08:00
parent 96319f0898
commit f8927e3193
15 changed files with 2041 additions and 146 deletions

View File

@@ -16,4 +16,8 @@ class Request extends \think\Request{
public function auth(){
return app()->make(UsersService::class)->getUserAuth($this->user['uid']);
}
public function static(){
return $this->domain() . '/storage/';
}
}

View File

@@ -29,6 +29,8 @@ class Index extends Base{
}
public function member(){
// $output = $this->app->console->call('migrate:run');
// return $output->fetch();
// $map = [];
// $member = Member::where($map)->select();
// $save = [];

View File

@@ -9,6 +9,7 @@
namespace app\controller\system;
use app\controller\Base;
use app\validate\File as Files;
use app\services\system\DictionaryService;
/**
@@ -16,4 +17,54 @@ use app\services\system\DictionaryService;
*/
class File extends Base{
/**
* @title 上传
*
* @return void
*/
public function upload(){
$file = request()->file('file');
$type = request()->param('type', 'images');
try {
$this->data['data'] = $this->$type($file, $type);
} catch (\think\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 用户头像上传
*
* @return void
*/
protected function avatar($file, $type){
try {
validate(Files::class)->check(['avatar' => $file]);
// 上传到本地服务器
$savename = \think\facade\Filesystem::putFile( $type, $file);
return ['src' => request()->static() . $savename, 'fileName' => ''];
} catch (\think\exception\ValidateException $e) {
throw new \think\Exception($e->getMessage(), 1);
}
}
/**
* @title 图片上传
*
* @return void
*/
protected function images($file, $type){
try {
validate(Files::class)->check(['image' => $file]);
// 上传到本地服务器
$savename = \think\facade\Filesystem::putFile( $type, $file);
return ['src' => request()->static() . $savename, 'fileName' => ''];
} catch (\think\exception\ValidateException $e) {
throw new \think\Exception($e->getMessage(), 1);
}
}
}

25
app/validate/File.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\validate;
use think\Validate;
class File extends Validate{
protected $rule = [
'avatar' => 'fileSize:102400|fileExt:jpg,png',
'image' => 'fileSize:204800|fileExt:jpg,jpeg,png,webp',
'file' => 'fileSize:1024 * 1000|fileExt:doc,xls,zip,rar'
];
protected $message = [
'avatar.fileSize' => '图片不大于1M',
'avatar.fileExt' => '头像后缀不正确',
'avatar.image' => '头像尺寸不正确',
];
}