作者 lyh

gx

@@ -293,21 +293,23 @@ class FileController @@ -293,21 +293,23 @@ 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 }
304 - $fileName = basename($info['path']); // 要保存的文件名  
305 - // 设置响应头  
306 - header('Content-Type: application/octet-stream');  
307 - header('Content-Disposition: attachment; filename="' . $fileName . '"');  
308 - // 下载文件  
309 - readfile($fileUrl);  
310 } 305 }
  306 + $fileName = basename($info['path']); // 要保存的文件名
  307 + // 设置响应头
  308 + header('Content-Description: File Transfer');
  309 + header('Content-Type: application/octet-stream');
  310 + header('Content-Disposition: attachment; filename="' . $fileName . '"');
  311 + // 下载文件
  312 + readfile($fileUrl);
311 } 313 }
312 314
313 /** 315 /**
@@ -60,24 +60,5 @@ class CosService @@ -60,24 +60,5 @@ class CosService
60 $imageUrl = $cosClient->getObjectUrl($cos['bucket'], trim($image_name,'/'), '+10 years'); 60 $imageUrl = $cosClient->getObjectUrl($cos['bucket'], trim($image_name,'/'), '+10 years');
61 return $imageUrl; 61 return $imageUrl;
62 } 62 }
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 - } 63 +
83 } 64 }