作者 lyh

gx

... ... @@ -46,18 +46,6 @@ class FileController
$this->uploads = config('upload.default_file');
$this->token = $this->request->header('token');
$this->cache = Cache::get($this->token);
if(!isset($this->token) || empty($this->cache)){
$this->response('请登录后上传',Code::USER_LOGIN_ERROE);
}
//上传路径设置
if(!isset($this->param['image_type'])){
$this->response('类型不能为空',Code::USER_ERROR);
}
if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){
$this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['file_type']].'/'.date('Y-m');
}else{
$this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['file_type']].'/'.date('Y-m');
}
}
/**
... ... @@ -146,11 +134,11 @@ class FileController
'file.required'=>'必须填写',
]);
$files = $this->param['file'];
if (empty($files)) {
$this->response('没有上传的文件!', 400);
}
$type = $this->request->post('type','single');
$this->setUrl();
if ($type == 'multi') {
return $this->multi($files);
} else {
... ... @@ -174,7 +162,7 @@ class FileController
if($file_hash !== false){
return $this->response('资源',Code::SUCCESS,['file'=>$hash]);
}
$url = $this->config['url'].'/'.$this->path;
$url = $this->config['root'].$this->path;
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
$res = $files->move($url,$fileName);
if ($res === false) {
... ... @@ -316,4 +304,22 @@ class FileController
// 下载文件
readfile($fileUrl);
}
/**
* @remark :保存路径
* @name :setUrl
* @author :lyh
* @method :post
* @time :2023/7/18 15:36
*/
public function setUrl(){
if(!isset($this->param['refer'])){
$this->param['refer'] = 1;
}
if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){
$this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m');
}else{
$this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m');
}
}
}
... ...