正在显示
1 个修改的文件
包含
8 行增加
和
14 行删除
| @@ -64,13 +64,16 @@ class FileManageController extends BaseController | @@ -64,13 +64,16 @@ class FileManageController extends BaseController | ||
| 64 | */ | 64 | */ |
| 65 | public function downLoad() | 65 | public function downLoad() |
| 66 | { | 66 | { |
| 67 | - if(!isset($this->param['path']) || empty($this->param['path'])){ | ||
| 68 | - $this->response('参数错误',Code::SYSTEM_ERROR); | 67 | + // 检查参数 |
| 68 | + if (!isset($this->param['path']) || empty($this->param['path'])) { | ||
| 69 | + $this->response('参数错误', Code::SYSTEM_ERROR); | ||
| 69 | } | 70 | } |
| 71 | + // 获取文件名和 URL | ||
| 70 | $username = basename($this->param['path']); | 72 | $username = basename($this->param['path']); |
| 71 | $parsed_url = parse_url($this->param['path']); | 73 | $parsed_url = parse_url($this->param['path']); |
| 72 | - if(isset($parsed_url['scheme'])){ | ||
| 73 | - $fileUrl = $this->param['path']; | 74 | + $fileUrl = isset($parsed_url['scheme']) |
| 75 | + ? $this->param['path'] | ||
| 76 | + : 'https://file.globalso.com' . $this->param['path']; | ||
| 74 | // 获取文件头信息 | 77 | // 获取文件头信息 |
| 75 | $headers = get_headers($fileUrl, 1); | 78 | $headers = get_headers($fileUrl, 1); |
| 76 | if ($headers === false || !isset($headers['Content-Length'])) { | 79 | if ($headers === false || !isset($headers['Content-Length'])) { |
| @@ -93,7 +96,7 @@ class FileManageController extends BaseController | @@ -93,7 +96,7 @@ class FileManageController extends BaseController | ||
| 93 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); | 96 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); |
| 94 | curl_setopt($ch, CURLOPT_HEADER, false); | 97 | curl_setopt($ch, CURLOPT_HEADER, false); |
| 95 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | 98 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
| 96 | - curl_setopt($ch, CURLOPT_BUFFERSIZE, 18192); // 设置缓冲区大小 | 99 | + curl_setopt($ch, CURLOPT_BUFFERSIZE, 8192); // 设置缓冲区大小 |
| 97 | curl_setopt($ch, CURLOPT_TIMEOUT, 300); // 设置超时时间 | 100 | curl_setopt($ch, CURLOPT_TIMEOUT, 300); // 设置超时时间 |
| 98 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); | 101 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); |
| 99 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | 102 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| @@ -118,15 +121,6 @@ class FileManageController extends BaseController | @@ -118,15 +121,6 @@ class FileManageController extends BaseController | ||
| 118 | } | 121 | } |
| 119 | curl_close($ch); | 122 | curl_close($ch); |
| 120 | exit; | 123 | 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 | - } | ||
| 130 | } | 124 | } |
| 131 | 125 | ||
| 132 | 126 |
-
请 注册 或 登录 后发表评论