|
...
|
...
|
@@ -75,16 +75,15 @@ class FileManageController extends BaseController |
|
|
|
$fileUrl = isset($parsed_url['scheme'])
|
|
|
|
? $this->param['path']
|
|
|
|
: 'https://v6-file.globalso.com' . $this->param['path'];
|
|
|
|
|
|
|
|
// 获取文件头信息
|
|
|
|
// 获取文件头信息,验证文件可访问性
|
|
|
|
$headers = @get_headers($fileUrl, 1);
|
|
|
|
if (!$headers || empty($headers['Content-Length'])) {
|
|
|
|
$this->response('无法获取文件信息或文件不存在', Code::SYSTEM_ERROR);
|
|
|
|
@file_put_contents(storage_path('logs/lyh_error.log'), var_export('1-报错', true) . PHP_EOL, FILE_APPEND);
|
|
|
|
}
|
|
|
|
$fileSize = $headers['Content-Length'] ?? 0;
|
|
|
|
$contentType = $headers['Content-Type'] ?? 'application/octet-stream';
|
|
|
|
if ($fileSize <= 0) {
|
|
|
|
$this->response('文件大小无效', Code::SYSTEM_ERROR);
|
|
|
|
@file_put_contents(storage_path('logs/lyh_error.log'), var_export('2-报错', true) . PHP_EOL, FILE_APPEND);
|
|
|
|
}
|
|
|
|
// 设置响应头
|
|
|
|
header('Content-Description: File Transfer');
|
|
...
|
...
|
@@ -93,15 +92,15 @@ class FileManageController extends BaseController |
|
|
|
header('Content-Length: ' . $fileSize);
|
|
|
|
header('Cache-Control: must-revalidate');
|
|
|
|
header('Pragma: public');
|
|
|
|
header('Expires: 0');
|
|
|
|
// 初始化 cURL
|
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $fileUrl);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); // 直接输出内容
|
|
|
|
curl_setopt($ch, CURLOPT_HEADER, false);
|
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
curl_setopt($ch, CURLOPT_BUFFERSIZE, 8192); // 设置缓冲区大小
|
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 300); // 设置超时时间
|
|
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
// 分块输出文件内容
|
|
...
|
...
|
@@ -110,11 +109,11 @@ class FileManageController extends BaseController |
|
|
|
flush(); // 强制输出缓冲
|
|
|
|
return strlen($data);
|
|
|
|
});
|
|
|
|
// 清空缓冲区
|
|
|
|
// 清空输出缓冲
|
|
|
|
@ob_end_clean();
|
|
|
|
// 执行 cURL
|
|
|
|
curl_exec($ch);
|
|
|
|
// 检查 HTTP 状态码和 cURL 错误
|
|
|
|
// 检查 cURL 错误或 HTTP 状态码
|
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
if (curl_errno($ch) || $httpCode != 200) {
|
|
|
|
$errorMsg = curl_errno($ch)
|
|
...
|
...
|
@@ -132,6 +131,7 @@ class FileManageController extends BaseController |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function upload(Request $request, FileManage $fileManage){
|
|
|
|
$request->validate([
|
|
|
|
'file'=>['required'],
|
...
|
...
|
|