This commit is contained in:
2025-12-24 16:59:05 +08:00
parent b52a51c09b
commit b68946fe79
218 changed files with 10790 additions and 3878 deletions
+39 -4
View File
@@ -5,6 +5,7 @@ use support\Response;
use Shopwwi\WebmanFilesystem\FilesystemFactory;
use Shopwwi\WebmanFilesystem\Facade\Storage;
use hg\apidoc\annotation as Apidoc;
use taoser\facade\Validate;
/**
* 基础控制器
* @Apidoc\NotParse()
@@ -62,14 +63,48 @@ class BaseController
*/
function upload(Request $request)
{
try{
$user = \support\Jwt::getUser();
}catch(\Exception $e){
$user = ['id'=>0];
}
$savePath = $request->post('savePath','files');
$validate = Validate::rule('savePath', 'alphaNum');
$data = ['savePath' => $savePath];
if (!$validate->check($data)) {
return $this->fail( '参数错误:'.$validate->getError());
}
$savePath = trim($savePath,'/');
$savePath = 'upload/'.$savePath.'/'.$user['id'];
\support\Log::alert('savePath:'.$savePath);
$mimetype = explode(',',Config('site.upload_mimetype'));
$maxsize = Config('site.upload_maxsize')*1024*1024;
//多文件上传
$files = $request->file();
try {
$result = Storage::adapter('public')
->path('upload/files')
->size(1024*1024*10)
->extYes(['image/jpeg','image/png'])
->uploads($files,0,1024*1024*100,false);
->path($savePath)
->size($maxsize)
->extYes($mimetype)
->uploads($files,0,$maxsize * count($files),false);
$save_datas = [];
foreach($result as $k=>$fileinfo){
$save_datas[] = [
'user_id' => $user['id'],
'category' => 'default',
'title' => $fileinfo->origin_name,
'path' => $fileinfo->file_name,
'size' => $fileinfo->size,
'mime_type' => $fileinfo->mime_type,
'extension' => $fileinfo->extension,
'height' => $fileinfo->file_height,
'width' => $fileinfo->file_width,
'sha1' => sha1_file(public_path($fileinfo->file_name)),
'use_count' => 0,
];
}
\app\model\Files::insertAll($save_datas);
return $this->success(__('successful'),$result);
}catch (\Exception $e){
return $this->error($e->getMessage());