From a4a088d2fbc360dc3b52f5a1581cf0911eb735f9 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq.com> Date: Wed, 15 Oct 2025 16:40:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=93=BE=E6=8E=A5=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=96=87=E4=BB=B6=E6=B5=81=E7=A8=8B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/Upload.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/common/controller/Upload.php b/app/common/controller/Upload.php index 4a6c5c2..4f675d7 100644 --- a/app/common/controller/Upload.php +++ b/app/common/controller/Upload.php @@ -32,7 +32,7 @@ class Upload extends BaseController /** * 文件上传 */ - public function upload($data,$path,$prefix = "",$fileObj = true) + public function upload($data,$path,$prefix = "",$fileObj = true, $oldFile = false) { $message=$data['message'] ?? ''; if($message){ @@ -83,10 +83,16 @@ class Upload extends BaseController if(!$prefix){ $prefix=$filecate.'/'.date('Y-m-d').'/'.$uid."/"; } - $name=str_replace('.'.$info['ext'],'',$info['name']); - $file=false;//FileModel::where(['md5'=>$info['md5'],'user_id'=>$uid])->find(); + if ($oldFile && !$fileObj) { + $rep_path = str_replace(public_path(),'',$path); + $file=FileModel::where(['src'=>$rep_path,'user_id'=>$uid])->find(); + $name=$file['name']; + } else { + $name=str_replace('.'.$info['ext'],'',$info['name']); + $file=FileModel::where(['md5'=>$info['md5'],'user_id'=>$uid])->find(); + } // 判断文件是否存在,如果有则不再上传 - if(!$file){ + if($filecate == 'image' || !$file){ $newName = uniqid() . '.' . $info['ext']; $object = $prefix . $newName; if($this->disk=='local'){ @@ -216,7 +222,7 @@ class Upload extends BaseController } elseif ($type == 'file') { $main_host = getMainHost(); $path = public_path() . '/' . ltrim(str_replace($main_host,'',$image_url),'/'); - $info = $this->upload($param,$path,'', false); + $info = $this->upload($param,$path,'', false, true); } else { throw new \Exception(lang('file.error')); }