|
@@ -110,11 +110,12 @@ class FileController |
|
@@ -110,11 +110,12 @@ class FileController |
|
110
|
*/
|
110
|
*/
|
|
111
|
public function single(&$files){
|
111
|
public function single(&$files){
|
|
112
|
$hash = hash_file('md5', $files->getPathname());
|
112
|
$hash = hash_file('md5', $files->getPathname());
|
|
|
|
113
|
+ $name = $files->getClientOriginalName();
|
|
113
|
//查看文件是否存在
|
114
|
//查看文件是否存在
|
|
114
|
$fileModel = new File();
|
115
|
$fileModel = new File();
|
|
115
|
$file_hash = $fileModel->read(['hash'=>$hash]);
|
116
|
$file_hash = $fileModel->read(['hash'=>$hash]);
|
|
116
|
if($file_hash !== false){
|
117
|
if($file_hash !== false){
|
|
117
|
- return $this->response('资源',Code::SUCCESS,$this->responseData($file_hash['path']));
|
118
|
+ return $this->response('资源',Code::SUCCESS,$this->responseData($file_hash['path'], $name));
|
|
118
|
}
|
119
|
}
|
|
119
|
$url = $this->config['root'].$this->path;
|
120
|
$url = $this->config['root'].$this->path;
|
|
120
|
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
|
121
|
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
|
|
@@ -128,8 +129,8 @@ class FileController |
|
@@ -128,8 +129,8 @@ class FileController |
|
128
|
return $this->response($files->getError(), Code::USER_ERROR);
|
129
|
return $this->response($files->getError(), Code::USER_ERROR);
|
|
129
|
}
|
130
|
}
|
|
130
|
}
|
131
|
}
|
|
131
|
- $this->saveMysql($fileModel,$files->getSize(),$files->getClientOriginalExtension(),$fileName,$hash,$this->upload_location,$files->getMimeType());
|
|
|
|
132
|
- return $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));
|
132
|
+ $this->saveMysql($fileModel,$files->getSize(),$files->getClientOriginalExtension(),$fileName,$hash,$this->upload_location,$files->getMimeType(),$name);
|
|
|
|
133
|
+ return $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name));
|
|
133
|
}
|
134
|
}
|
|
134
|
|
135
|
|
|
135
|
/**
|
136
|
/**
|
|
@@ -139,7 +140,7 @@ class FileController |
|
@@ -139,7 +140,7 @@ class FileController |
|
139
|
* @method :post
|
140
|
* @method :post
|
|
140
|
* @time :2023/7/19 16:38
|
141
|
* @time :2023/7/19 16:38
|
|
141
|
*/
|
142
|
*/
|
|
142
|
- public function saveMysql(&$fileModel,$size,$image_type,$fileName,$hash,$is_cos = 0,$mime = ''){
|
143
|
+ public function saveMysql(&$fileModel,$size,$image_type,$fileName,$hash,$is_cos = 0,$mime = '',$name=''){
|
|
143
|
$data = [
|
144
|
$data = [
|
|
144
|
'path' => $this->path.'/'.$fileName,
|
145
|
'path' => $this->path.'/'.$fileName,
|
|
145
|
'created_at' => date('Y-m-d H:i:s',time()),
|
146
|
'created_at' => date('Y-m-d H:i:s',time()),
|
|
@@ -149,6 +150,7 @@ class FileController |
|
@@ -149,6 +150,7 @@ class FileController |
|
149
|
'refer'=>$this->param['refer'] ?? 1,
|
150
|
'refer'=>$this->param['refer'] ?? 1,
|
|
150
|
'is_cos'=>$is_cos,
|
151
|
'is_cos'=>$is_cos,
|
|
151
|
'mime'=>$mime,
|
152
|
'mime'=>$mime,
|
|
|
|
153
|
+ 'name'=>$name,
|
|
152
|
];
|
154
|
];
|
|
153
|
$rs = $fileModel->add($data);
|
155
|
$rs = $fileModel->add($data);
|
|
154
|
if ($rs === false) {
|
156
|
if ($rs === false) {
|
|
@@ -168,10 +170,11 @@ class FileController |
|
@@ -168,10 +170,11 @@ class FileController |
|
168
|
$data = [];
|
170
|
$data = [];
|
|
169
|
foreach ($files as $file) {
|
171
|
foreach ($files as $file) {
|
|
170
|
$fileModel = new File();
|
172
|
$fileModel = new File();
|
|
|
|
173
|
+ $name = $file->getClientOriginalName();
|
|
171
|
$hash = hash_file('md5', $file->getPathname());
|
174
|
$hash = hash_file('md5', $file->getPathname());
|
|
172
|
$file_hash = $fileModel->read(['hash'=>$hash]);
|
175
|
$file_hash = $fileModel->read(['hash'=>$hash]);
|
|
173
|
if($file_hash !== false){
|
176
|
if($file_hash !== false){
|
|
174
|
- $data[] = $this->responseData($file_hash['path']);
|
177
|
+ $data[] = $this->responseData($file_hash['path'], $name);
|
|
175
|
continue;
|
178
|
continue;
|
|
176
|
}
|
179
|
}
|
|
177
|
$url = $this->config['root'].'/'.$this->path;
|
180
|
$url = $this->config['root'].'/'.$this->path;
|
|
@@ -189,8 +192,8 @@ class FileController |
|
@@ -189,8 +192,8 @@ class FileController |
|
189
|
}
|
192
|
}
|
|
190
|
$size = $file->getSize();
|
193
|
$size = $file->getSize();
|
|
191
|
$mime = $file->getMimeType();
|
194
|
$mime = $file->getMimeType();
|
|
192
|
- $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location,$mime);
|
|
|
|
193
|
- $data[] = $this->responseData($this->path.'/'.$fileName);
|
195
|
+ $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location,$mime,$name);
|
|
|
|
196
|
+ $data[] = $this->responseData($this->path.'/'.$fileName, $name);
|
|
194
|
}
|
197
|
}
|
|
195
|
$this->response('资源',Code::SUCCESS,$data);
|
198
|
$this->response('资源',Code::SUCCESS,$data);
|
|
196
|
}
|
199
|
}
|
|
@@ -230,11 +233,11 @@ class FileController |
|
@@ -230,11 +233,11 @@ class FileController |
|
230
|
$this->response('指定文件不存在!', Code::USER_ERROR);
|
233
|
$this->response('指定文件不存在!', Code::USER_ERROR);
|
|
231
|
}
|
234
|
}
|
|
232
|
$fileUrl = getFileUrl($info['path'],$info['is_cos']);
|
235
|
$fileUrl = getFileUrl($info['path'],$info['is_cos']);
|
|
233
|
- $fileName = basename($fileUrl); // 要保存的文件名
|
236
|
+// $fileName = basename($fileUrl); // 要保存的文件名
|
|
234
|
// 设置响应头
|
237
|
// 设置响应头
|
|
235
|
header('Content-Description: File Transfer');
|
238
|
header('Content-Description: File Transfer');
|
|
236
|
header('Content-Type: application/octet-stream');
|
239
|
header('Content-Type: application/octet-stream');
|
|
237
|
- header('Content-Disposition: attachment; filename="' . $fileName . '"');
|
240
|
+ header('Content-Disposition: attachment; filename="' . $info['name'] . '"');
|
|
238
|
// 下载文件
|
241
|
// 下载文件
|
|
239
|
readfile($fileUrl);
|
242
|
readfile($fileUrl);
|
|
240
|
}
|
243
|
}
|
|
@@ -277,7 +280,7 @@ class FileController |
|
@@ -277,7 +280,7 @@ class FileController |
|
277
|
}
|
280
|
}
|
|
278
|
$this->map['refer'] = 1;
|
281
|
$this->map['refer'] = 1;
|
|
279
|
$fileModel = new File();
|
282
|
$fileModel = new File();
|
|
280
|
- $lists = $fileModel->list($this->map,'id',['id','hash','type','path','created_at']);
|
283
|
+ $lists = $fileModel->list($this->map,'id',['id','hash','type','path','created_at','name']);
|
|
281
|
foreach ($lists as $k => $v){
|
284
|
foreach ($lists as $k => $v){
|
|
282
|
$v['file_link'] = getFileUrl($v['path']);
|
285
|
$v['file_link'] = getFileUrl($v['path']);
|
|
283
|
$lists[$k] = $v;
|
286
|
$lists[$k] = $v;
|
|
@@ -292,10 +295,11 @@ class FileController |
|
@@ -292,10 +295,11 @@ class FileController |
|
292
|
* @method :post
|
295
|
* @method :post
|
|
293
|
* @time :2023/7/26 13:41
|
296
|
* @time :2023/7/26 13:41
|
|
294
|
*/
|
297
|
*/
|
|
295
|
- public function responseData($path){
|
298
|
+ public function responseData($path, $name){
|
|
296
|
$data = [
|
299
|
$data = [
|
|
297
|
'file'=>$path,
|
300
|
'file'=>$path,
|
|
298
|
'file_link'=>getFileUrl($path,$this->upload_location),
|
301
|
'file_link'=>getFileUrl($path,$this->upload_location),
|
|
|
|
302
|
+ 'name'=>$name,
|
|
299
|
];
|
303
|
];
|
|
300
|
return $data;
|
304
|
return $data;
|
|
301
|
}
|
305
|
}
|
|
@@ -313,7 +317,7 @@ class FileController |
|
@@ -313,7 +317,7 @@ class FileController |
|
313
|
if ($info === false) {
|
317
|
if ($info === false) {
|
|
314
|
$this->response('指定文件不存在!', Code::USER_ERROR);
|
318
|
$this->response('指定文件不存在!', Code::USER_ERROR);
|
|
315
|
}
|
319
|
}
|
|
316
|
- $data = ['file_download'=>url('a/download_files?path='.$info['path'])];
|
320
|
+ $data = ['file_download'=>url('a/download_files?path='.$info['path']), 'name' => $info['name']];
|
|
317
|
$this->response('success',Code::SUCCESS,$data);
|
321
|
$this->response('success',Code::SUCCESS,$data);
|
|
318
|
}
|
322
|
}
|
|
319
|
} |
323
|
} |