作者 lyh

gx

@@ -46,18 +46,6 @@ class FileController @@ -46,18 +46,6 @@ class FileController
46 $this->uploads = config('upload.default_file'); 46 $this->uploads = config('upload.default_file');
47 $this->token = $this->request->header('token'); 47 $this->token = $this->request->header('token');
48 $this->cache = Cache::get($this->token); 48 $this->cache = Cache::get($this->token);
49 - if(!isset($this->token) || empty($this->cache)){  
50 - $this->response('请登录后上传',Code::USER_LOGIN_ERROE);  
51 - }  
52 - //上传路径设置  
53 - if(!isset($this->param['image_type'])){  
54 - $this->response('类型不能为空',Code::USER_ERROR);  
55 - }  
56 - if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){  
57 - $this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['file_type']].'/'.date('Y-m');  
58 - }else{  
59 - $this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['file_type']].'/'.date('Y-m');  
60 - }  
61 } 49 }
62 50
63 /** 51 /**
@@ -146,11 +134,11 @@ class FileController @@ -146,11 +134,11 @@ class FileController
146 'file.required'=>'必须填写', 134 'file.required'=>'必须填写',
147 ]); 135 ]);
148 $files = $this->param['file']; 136 $files = $this->param['file'];
149 -  
150 if (empty($files)) { 137 if (empty($files)) {
151 $this->response('没有上传的文件!', 400); 138 $this->response('没有上传的文件!', 400);
152 } 139 }
153 $type = $this->request->post('type','single'); 140 $type = $this->request->post('type','single');
  141 + $this->setUrl();
154 if ($type == 'multi') { 142 if ($type == 'multi') {
155 return $this->multi($files); 143 return $this->multi($files);
156 } else { 144 } else {
@@ -174,7 +162,7 @@ class FileController @@ -174,7 +162,7 @@ class FileController
174 if($file_hash !== false){ 162 if($file_hash !== false){
175 return $this->response('资源',Code::SUCCESS,['file'=>$hash]); 163 return $this->response('资源',Code::SUCCESS,['file'=>$hash]);
176 } 164 }
177 - $url = $this->config['url'].'/'.$this->path; 165 + $url = $this->config['root'].$this->path;
178 $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension(); 166 $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
179 $res = $files->move($url,$fileName); 167 $res = $files->move($url,$fileName);
180 if ($res === false) { 168 if ($res === false) {
@@ -316,4 +304,22 @@ class FileController @@ -316,4 +304,22 @@ class FileController
316 // 下载文件 304 // 下载文件
317 readfile($fileUrl); 305 readfile($fileUrl);
318 } 306 }
  307 +
  308 + /**
  309 + * @remark :保存路径
  310 + * @name :setUrl
  311 + * @author :lyh
  312 + * @method :post
  313 + * @time :2023/7/18 15:36
  314 + */
  315 + public function setUrl(){
  316 + if(!isset($this->param['refer'])){
  317 + $this->param['refer'] = 1;
  318 + }
  319 + if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){
  320 + $this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m');
  321 + }else{
  322 + $this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m');
  323 + }
  324 + }
319 } 325 }