作者 lyh

gx

@@ -293,22 +293,24 @@ class FileController @@ -293,22 +293,24 @@ class FileController
293 if ($info === false) { 293 if ($info === false) {
294 $this->response('指定文件不存在!', Code::USER_ERROR); 294 $this->response('指定文件不存在!', Code::USER_ERROR);
295 } 295 }
  296 +
296 if($info['is_cos'] == 1){ 297 if($info['is_cos'] == 1){
297 $cos = new CosService(); 298 $cos = new CosService();
298 - return $cos->downloadFile($info['path']); 299 + $fileUrl = $cos->getImageUrl($info['path']);
299 }else{ 300 }else{
300 $fileUrl = $this->config['root'].$info['path']; 301 $fileUrl = $this->config['root'].$info['path'];
301 if (!is_file($fileUrl)) { 302 if (!is_file($fileUrl)) {
302 $this->response('指定文件已被系统删除!', Code::USER_ERROR); 303 $this->response('指定文件已被系统删除!', Code::USER_ERROR);
303 } 304 }
  305 + }
304 $fileName = basename($info['path']); // 要保存的文件名 306 $fileName = basename($info['path']); // 要保存的文件名
305 // 设置响应头 307 // 设置响应头
  308 + header('Content-Description: File Transfer');
306 header('Content-Type: application/octet-stream'); 309 header('Content-Type: application/octet-stream');
307 header('Content-Disposition: attachment; filename="' . $fileName . '"'); 310 header('Content-Disposition: attachment; filename="' . $fileName . '"');
308 // 下载文件 311 // 下载文件
309 readfile($fileUrl); 312 readfile($fileUrl);
310 } 313 }
311 - }  
312 314
313 /** 315 /**
314 * @remark :保存路径 316 * @remark :保存路径
@@ -61,23 +61,4 @@ class CosService @@ -61,23 +61,4 @@ class CosService
61 return $imageUrl; 61 return $imageUrl;
62 } 62 }
63 63
64 - /**  
65 - * @remark :下载文件  
66 - * @name :downloadFile  
67 - * @author :lyh  
68 - * @method :post  
69 - * @time :2023/7/21 14:56  
70 - */  
71 - public function downloadFile($file_name){  
72 - $cos = config('filesystems.disks.cos');  
73 - $cosClient = new Client([  
74 - 'region' => $cos['region'],  
75 - 'credentials' => [  
76 - 'secretId' => $cos['credentials']['secretId'],  
77 - 'secretKey' => $cos['credentials']['secretKey'],  
78 - ],  
79 - ]);  
80 - $saveAs = basename($file_name);  
81 - return $cosClient->getObject(['Bucket' => $cos['bucket'], 'Key' => trim($file_name,'/'), 'SaveAs' => $saveAs]);  
82 - }  
83 } 64 }