From c483aa782c7efcb1c43f52a58c1f10898758c13c Mon Sep 17 00:00:00 2001 From: Ying Date: Wed, 21 Dec 2022 19:43:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E5=88=86=E9=85=8D?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=90=8D=E7=A7=B0=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/library/Upload.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/common/library/Upload.php b/app/common/library/Upload.php index 99c5721..1d2a429 100644 --- a/app/common/library/Upload.php +++ b/app/common/library/Upload.php @@ -277,6 +277,8 @@ class Upload try { $this->getFileSavePath($file); + // 分片上传使用ID作为文件名 + $this->resource = $this->filepath . DS . sha1($params['chunkId']) . '.' . $fileExt; $file->move($this->resource); } catch (\Exception $e) { Event::emit('uploadExceptionDelete', [ @@ -352,16 +354,17 @@ class Upload /** * 附件数据库保存 - * @param $file + * @param $filePath * @param string $source * @param string|null $mimeType * @return false|void */ - public function attachment($file, string $source, string $mimeType = null) + public function attachment($filePath, string $source, string $mimeType = null) { try { - $file = new \Webman\Http\UploadFile($file, $source, $mimeType, 200); - $filePath = str_replace('\\', '/', $this->filepath . DS . $this->filename); + $file = new \Webman\Http\UploadFile($filePath, $source, $mimeType, 200); + $filePath = str_replace(public_path(), '', $filePath); + $filePath = str_replace('\\', '/', $filePath); $this->fileInfo = [ 'type' => $this->fileClass, 'filename' => $file->getUploadName(), @@ -372,6 +375,7 @@ class Upload 'user_id' => request()->cookie('uid') ?? 0, 'sha1' => md5_file($file->getPathname()), ]; + Attachment::create($this->fileInfo); } catch (\Exception $e) { $this->setError($e->getMessage());