正在显示
1 个修改的文件
包含
13 行增加
和
7 行删除
| @@ -64,16 +64,13 @@ class FileManageController extends BaseController | @@ -64,16 +64,13 @@ class FileManageController extends BaseController | ||
| 64 | */ | 64 | */ |
| 65 | public function downLoad() | 65 | public function downLoad() |
| 66 | { | 66 | { |
| 67 | - // 检查参数 | ||
| 68 | - if (!isset($this->param['path']) || empty($this->param['path'])) { | ||
| 69 | - $this->response('参数错误', Code::SYSTEM_ERROR); | 67 | + if(!isset($this->param['path']) || empty($this->param['path'])){ |
| 68 | + $this->response('参数错误',Code::SYSTEM_ERROR); | ||
| 70 | } | 69 | } |
| 71 | - // 获取文件名和 URL | ||
| 72 | $username = basename($this->param['path']); | 70 | $username = basename($this->param['path']); |
| 73 | $parsed_url = parse_url($this->param['path']); | 71 | $parsed_url = parse_url($this->param['path']); |
| 74 | - $fileUrl = isset($parsed_url['scheme']) | ||
| 75 | - ? $this->param['path'] | ||
| 76 | - : 'https://file.globalso.com' . $this->param['path']; | 72 | + if(isset($parsed_url['scheme'])){ |
| 73 | + $fileUrl = $this->param['path']; | ||
| 77 | // 获取文件头信息 | 74 | // 获取文件头信息 |
| 78 | $headers = get_headers($fileUrl, 1); | 75 | $headers = get_headers($fileUrl, 1); |
| 79 | if ($headers === false || !isset($headers['Content-Length'])) { | 76 | if ($headers === false || !isset($headers['Content-Length'])) { |
| @@ -121,6 +118,15 @@ class FileManageController extends BaseController | @@ -121,6 +118,15 @@ class FileManageController extends BaseController | ||
| 121 | } | 118 | } |
| 122 | curl_close($ch); | 119 | curl_close($ch); |
| 123 | exit; | 120 | exit; |
| 121 | + } else { | ||
| 122 | + $fileUrl = 'https://file.globalso.com'.$this->param['path']; | ||
| 123 | + // 设置响应头 | ||
| 124 | + header('Content-Description: File Transfer'); | ||
| 125 | + header('Content-Type: application/octet-stream'); | ||
| 126 | + header('Content-Disposition: attachment; filename="' . $username . '"'); | ||
| 127 | + // 下载文件 | ||
| 128 | + readfile($fileUrl); | ||
| 129 | + } | ||
| 124 | } | 130 | } |
| 125 | 131 | ||
| 126 | 132 |
-
请 注册 或 登录 后发表评论