服务器文件上传

This commit is contained in:
2025-09-08 18:03:09 +08:00
parent efb4cde4f1
commit d6d421cba2
3 changed files with 104 additions and 8 deletions
+7 -4
View File
@@ -52,13 +52,13 @@ class UploadedFilesService
* 记录文件信息到数据库
*
* @param array $fileInfo 文件信息
* @param Request $request 请求对象
* @param Request|null $request 请求对象(可选)
* @param string $partition 分区名称
* @param string $category 文件分类
* @return array
* @throws BusinessException
*/
public function recordFileInfo(array $fileInfo, Request $request, string $partition = 'other', string $category = 'general'): array
public function recordFileInfo(array $fileInfo, ?Request $request = null, string $partition = 'other', string $category = 'general'): array
{
// 验证必需的文件信息
@@ -73,6 +73,9 @@ class UploadedFilesService
$fileExtension = pathinfo($fileInfo['file_name'], PATHINFO_EXTENSION);
// 记录到数据库
$uploadIp = $request ? $request->getRealIp() : '0.0.0.0';
$userAgent = $request ? $request->header('User-Agent', '') : '';
$fileData = [
'file_name' => $fileInfo['file_name'],
'file_path' => $fileInfo['file_path'],
@@ -82,8 +85,8 @@ class UploadedFilesService
'original_name' => $fileInfo['original_name'] ?? '',
'extension' => $fileExtension,
'partition' => $partition,
'upload_ip' => $request->getRealIp(),
'user_agent' => $request->header('User-Agent', ''),
'upload_ip' => $uploadIp,
'user_agent' => $userAgent,
];
$uploadedFile = $this->logicCreate($fileData);