作者 lyh

gxdemo脚本

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