|
@@ -62,25 +62,49 @@ class FileManageController extends BaseController |
|
@@ -62,25 +62,49 @@ class FileManageController extends BaseController |
|
62
|
* @method :post
|
62
|
* @method :post
|
|
63
|
* @time :2023/12/28 17:18
|
63
|
* @time :2023/12/28 17:18
|
|
64
|
*/
|
64
|
*/
|
|
65
|
- public function downLoad(){
|
|
|
|
66
|
- if(!isset($this->param['path']) || empty($this->param['path'])){
|
|
|
|
67
|
- $this->response('参数错误',Code::SYSTEM_ERROR);
|
65
|
+ public function downLoad()
|
|
|
|
66
|
+ {
|
|
|
|
67
|
+ // 检查参数
|
|
|
|
68
|
+ if (!isset($this->param['path']) || empty($this->param['path'])) {
|
|
|
|
69
|
+ $this->response('参数错误', Code::SYSTEM_ERROR);
|
|
68
|
}
|
70
|
}
|
|
69
|
$username = basename($this->param['path']);
|
71
|
$username = basename($this->param['path']);
|
|
70
|
$parsed_url = parse_url($this->param['path']);
|
72
|
$parsed_url = parse_url($this->param['path']);
|
|
71
|
- if(isset($parsed_url['scheme'])){
|
|
|
|
72
|
- $fileUrl = $this->param['path'];
|
|
|
|
73
|
- } else {
|
|
|
|
74
|
- $fileUrl = 'https://file.globalso.com'.$this->param['path'];
|
73
|
+ // 构造文件 URL
|
|
|
|
74
|
+ $fileUrl = isset($parsed_url['scheme'])
|
|
|
|
75
|
+ ? $this->param['path']
|
|
|
|
76
|
+ : 'https://file.globalso.com' . $this->param['path'];
|
|
|
|
77
|
+ // 初始化 curl
|
|
|
|
78
|
+ $ch = curl_init();
|
|
|
|
79
|
+ curl_setopt($ch, CURLOPT_URL, $fileUrl);
|
|
|
|
80
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
81
|
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
82
|
+ curl_setopt($ch, CURLOPT_HEADER, false);
|
|
|
|
83
|
+ // 跳过 SSL 验证
|
|
|
|
84
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
85
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
86
|
+ // 执行 curl 请求
|
|
|
|
87
|
+ $fileContent = curl_exec($ch);
|
|
|
|
88
|
+ $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
89
|
+ $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
|
|
|
|
90
|
+ $curlError = curl_error($ch);
|
|
|
|
91
|
+ curl_close($ch);
|
|
|
|
92
|
+ // 检查 curl 错误或 HTTP 状态码
|
|
|
|
93
|
+ if ($fileContent === false || $httpCode != 200) {
|
|
|
|
94
|
+ $errorMsg = $fileContent === false ? "Curl Error: $curlError" : "HTTP Error: $httpCode";
|
|
|
|
95
|
+ $this->response("文件下载失败 - $errorMsg", Code::SYSTEM_ERROR);
|
|
75
|
}
|
96
|
}
|
|
76
|
// 设置响应头
|
97
|
// 设置响应头
|
|
77
|
header('Content-Description: File Transfer');
|
98
|
header('Content-Description: File Transfer');
|
|
78
|
- header('Content-Type: application/octet-stream');
|
99
|
+ header('Content-Type: ' . ($contentType ?: 'application/octet-stream'));
|
|
79
|
header('Content-Disposition: attachment; filename="' . $username . '"');
|
100
|
header('Content-Disposition: attachment; filename="' . $username . '"');
|
|
80
|
- // 下载文件
|
|
|
|
81
|
- readfile($fileUrl);
|
101
|
+ header('Content-Length: ' . strlen($fileContent));
|
|
|
|
102
|
+ // 输出文件内容
|
|
|
|
103
|
+ echo $fileContent;
|
|
|
|
104
|
+ exit;
|
|
82
|
}
|
105
|
}
|
|
83
|
|
106
|
|
|
|
|
107
|
+
|
|
84
|
public function upload(Request $request, FileManage $fileManage){
|
108
|
public function upload(Request $request, FileManage $fileManage){
|
|
85
|
$request->validate([
|
109
|
$request->validate([
|
|
86
|
'file'=>['required'],
|
110
|
'file'=>['required'],
|