Browse Source

新增链接上传文件流程2

master
wanghongjun 2 months ago
parent
commit
a4a088d2fb
  1. 16
      app/common/controller/Upload.php

16
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'));
}

Loading…
Cancel
Save