|
...
|
...
|
@@ -110,11 +110,12 @@ class FileController |
|
|
|
*/
|
|
|
|
public function single(&$files){
|
|
|
|
$hash = hash_file('md5', $files->getPathname());
|
|
|
|
$name = $files->getClientOriginalName();
|
|
|
|
//查看文件是否存在
|
|
|
|
$fileModel = new File();
|
|
|
|
$file_hash = $fileModel->read(['hash'=>$hash]);
|
|
|
|
if($file_hash !== false){
|
|
|
|
return $this->response('资源',Code::SUCCESS,$this->responseData($file_hash['path']));
|
|
|
|
return $this->response('资源',Code::SUCCESS,$this->responseData($file_hash['path'], $name));
|
|
|
|
}
|
|
|
|
$url = $this->config['root'].$this->path;
|
|
|
|
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
|
|
...
|
...
|
@@ -128,8 +129,8 @@ class FileController |
|
|
|
return $this->response($files->getError(), Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->saveMysql($fileModel,$files->getSize(),$files->getClientOriginalExtension(),$fileName,$hash,$this->upload_location,$files->getMimeType());
|
|
|
|
return $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));
|
|
|
|
$this->saveMysql($fileModel,$files->getSize(),$files->getClientOriginalExtension(),$fileName,$hash,$this->upload_location,$files->getMimeType(),$name);
|
|
|
|
return $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -139,7 +140,7 @@ class FileController |
|
|
|
* @method :post
|
|
|
|
* @time :2023/7/19 16:38
|
|
|
|
*/
|
|
|
|
public function saveMysql(&$fileModel,$size,$image_type,$fileName,$hash,$is_cos = 0,$mime = ''){
|
|
|
|
public function saveMysql(&$fileModel,$size,$image_type,$fileName,$hash,$is_cos = 0,$mime = '',$name=''){
|
|
|
|
$data = [
|
|
|
|
'path' => $this->path.'/'.$fileName,
|
|
|
|
'created_at' => date('Y-m-d H:i:s',time()),
|
|
...
|
...
|
@@ -149,6 +150,7 @@ class FileController |
|
|
|
'refer'=>$this->param['refer'] ?? 1,
|
|
|
|
'is_cos'=>$is_cos,
|
|
|
|
'mime'=>$mime,
|
|
|
|
'name'=>$name,
|
|
|
|
];
|
|
|
|
$rs = $fileModel->add($data);
|
|
|
|
if ($rs === false) {
|
|
...
|
...
|
@@ -168,10 +170,11 @@ class FileController |
|
|
|
$data = [];
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$fileModel = new File();
|
|
|
|
$name = $file->getClientOriginalName();
|
|
|
|
$hash = hash_file('md5', $file->getPathname());
|
|
|
|
$file_hash = $fileModel->read(['hash'=>$hash]);
|
|
|
|
if($file_hash !== false){
|
|
|
|
$data[] = $this->responseData($file_hash['path']);
|
|
|
|
$data[] = $this->responseData($file_hash['path'], $name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$url = $this->config['root'].'/'.$this->path;
|
|
...
|
...
|
@@ -189,8 +192,8 @@ class FileController |
|
|
|
}
|
|
|
|
$size = $file->getSize();
|
|
|
|
$mime = $file->getMimeType();
|
|
|
|
$this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location,$mime);
|
|
|
|
$data[] = $this->responseData($this->path.'/'.$fileName);
|
|
|
|
$this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location,$mime,$name);
|
|
|
|
$data[] = $this->responseData($this->path.'/'.$fileName, $name);
|
|
|
|
}
|
|
|
|
$this->response('资源',Code::SUCCESS,$data);
|
|
|
|
}
|
|
...
|
...
|
@@ -230,11 +233,11 @@ class FileController |
|
|
|
$this->response('指定文件不存在!', Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
$fileUrl = getFileUrl($info['path'],$info['is_cos']);
|
|
|
|
$fileName = basename($fileUrl); // 要保存的文件名
|
|
|
|
// $fileName = basename($fileUrl); // 要保存的文件名
|
|
|
|
// 设置响应头
|
|
|
|
header('Content-Description: File Transfer');
|
|
|
|
header('Content-Type: application/octet-stream');
|
|
|
|
header('Content-Disposition: attachment; filename="' . $fileName . '"');
|
|
|
|
header('Content-Disposition: attachment; filename="' . $info['name'] . '"');
|
|
|
|
// 下载文件
|
|
|
|
readfile($fileUrl);
|
|
|
|
}
|
|
...
|
...
|
@@ -277,7 +280,7 @@ class FileController |
|
|
|
}
|
|
|
|
$this->map['refer'] = 1;
|
|
|
|
$fileModel = new File();
|
|
|
|
$lists = $fileModel->list($this->map,'id',['id','hash','type','path','created_at']);
|
|
|
|
$lists = $fileModel->list($this->map,'id',['id','hash','type','path','created_at','name']);
|
|
|
|
foreach ($lists as $k => $v){
|
|
|
|
$v['file_link'] = getFileUrl($v['path']);
|
|
|
|
$lists[$k] = $v;
|
|
...
|
...
|
@@ -292,10 +295,11 @@ class FileController |
|
|
|
* @method :post
|
|
|
|
* @time :2023/7/26 13:41
|
|
|
|
*/
|
|
|
|
public function responseData($path){
|
|
|
|
public function responseData($path, $name){
|
|
|
|
$data = [
|
|
|
|
'file'=>$path,
|
|
|
|
'file_link'=>getFileUrl($path,$this->upload_location),
|
|
|
|
'name'=>$name,
|
|
|
|
];
|
|
|
|
return $data;
|
|
|
|
}
|
|
...
|
...
|
@@ -313,7 +317,7 @@ class FileController |
|
|
|
if ($info === false) {
|
|
|
|
$this->response('指定文件不存在!', Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
$data = ['file_download'=>url('a/download_files?path='.$info['path'])];
|
|
|
|
$data = ['file_download'=>url('a/download_files?path='.$info['path']), 'name' => $info['name']];
|
|
|
|
$this->response('success',Code::SUCCESS,$data);
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|