|
...
|
...
|
@@ -66,28 +66,31 @@ class FileManageController extends BaseController |
|
|
|
{
|
|
|
|
// 检查参数
|
|
|
|
if (!isset($this->param['path']) || empty($this->param['path'])) {
|
|
|
|
$this->response('参数错误', Code::SYSTEM_ERROR);
|
|
|
|
$this->response('参数错误:path 参数缺失或为空', Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
// 获取文件名和 URL
|
|
|
|
|
|
|
|
// 获取文件名和完整 URL
|
|
|
|
$username = basename($this->param['path']);
|
|
|
|
$parsed_url = parse_url($this->param['path']);
|
|
|
|
$fileUrl = isset($parsed_url['scheme'])
|
|
|
|
? $this->param['path']
|
|
|
|
: 'https://file.globalso.com' . $this->param['path'];
|
|
|
|
: 'https://v6-file.globalso.com' . $this->param['path'];
|
|
|
|
|
|
|
|
// 获取文件头信息
|
|
|
|
$headers = get_headers($fileUrl, 1);
|
|
|
|
if ($headers === false || !isset($headers['Content-Length'])) {
|
|
|
|
$this->response('无法获取文件信息', Code::SYSTEM_ERROR);
|
|
|
|
$headers = @get_headers($fileUrl, 1);
|
|
|
|
if (!$headers || empty($headers['Content-Length'])) {
|
|
|
|
$this->response('无法获取文件信息或文件不存在', Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
$fileSize = $headers['Content-Length'] ?? 0;
|
|
|
|
$contentType = $headers['Content-Type'] ?? 'application/octet-stream';
|
|
|
|
if ($fileSize <= 0) {
|
|
|
|
$this->response('文件大小无效', Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
// 设置响应头
|
|
|
|
header('Content-Description: File Transfer');
|
|
|
|
header('Content-Type: ' . $contentType);
|
|
|
|
header('Content-Disposition: attachment; filename="' . $username . '"');
|
|
|
|
if ($fileSize > 0) {
|
|
|
|
header('Content-Length: ' . $fileSize);
|
|
|
|
}
|
|
|
|
header('Cache-Control: must-revalidate');
|
|
|
|
header('Pragma: public');
|
|
|
|
// 初始化 cURL
|
|
...
|
...
|
@@ -104,11 +107,12 @@ class FileManageController extends BaseController |
|
|
|
// 分块输出文件内容
|
|
|
|
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $data) {
|
|
|
|
echo $data;
|
|
|
|
flush(); // 强制输出
|
|
|
|
flush(); // 强制输出缓冲
|
|
|
|
return strlen($data);
|
|
|
|
});
|
|
|
|
// 清空缓冲区
|
|
|
|
@ob_end_clean();
|
|
|
|
// 执行 cURL
|
|
|
|
ob_end_clean(); // 清空输出缓冲
|
|
|
|
curl_exec($ch);
|
|
|
|
// 检查 HTTP 状态码和 cURL 错误
|
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
...
|
...
|
@@ -119,6 +123,7 @@ class FileManageController extends BaseController |
|
|
|
curl_close($ch);
|
|
|
|
$this->response('文件下载失败: ' . $errorMsg, Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
// 关闭 cURL
|
|
|
|
curl_close($ch);
|
|
|
|
exit;
|
|
|
|
}
|
|
...
|
...
|
@@ -126,6 +131,7 @@ class FileManageController extends BaseController |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function upload(Request $request, FileManage $fileManage){
|
|
|
|
$request->validate([
|
|
|
|
'file'=>['required'],
|
...
|
...
|
|