0) { @ob_end_clean(); } ob_start(); header('Content-Type: application/json; charset=utf-8'); header('Cache-Control: no-store'); require_once __DIR__ . '/../core.php'; require_once __DIR__ . '/../lsky.php'; require_once __DIR__ . '/../gh_api.php'; $cfg = loadImgJson(); // 1) git 二进制是否可用 $gitOk = false; $gitVer = ''; $gitCmd = 'git --version'; if (function_exists('exec')) { $out = []; $ret = 0; @exec($gitCmd . ' 2>&1', $out, $ret); if ($ret === 0 && !empty($out)) { $gitOk = true; $gitVer = trim(implode(' ', $out)); } } elseif (function_exists('shell_exec')) { $out = @shell_exec($gitCmd . ' 2>&1'); if (is_string($out)) { $gitVer = trim($out); $gitOk = ($gitVer !== ''); } } // 2) imgrepo 配置 $ir = [ 'mode' => $cfg['imgrepo_mode'] ?? '', 'owner' => $cfg['imgrepo_owner'] ?? '', 'full' => $cfg['imgrepo_full'] ?? '', 'branch' => $cfg['imgrepo_branch'] ?? '', 'token' => (isset($cfg['imgrepo_token']) && $cfg['imgrepo_token'] !== '') ? substr($cfg['imgrepo_token'], 0, 4) . '****' : '', ]; // 3) 仓可达性(带 token GET raw 域名,不实际推) $reach = ''; $reachStatus = 0; if ($ir['full'] !== '' && $ir['owner'] !== '') { $rawUrl = 'https://raw.githubusercontent.com/' . $ir['full'] . '/' . $ir['branch']; if (function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $rawUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 20); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_exec($ch); $reachStatus = (int)curl_getinfo($ch, CURLINFO_RESPONSE_CODE); $reach = 'HTTP ' . $reachStatus; curl_close($ch); } } success([ 'git_available' => $gitOk, 'git_version' => $gitVer, 'exec_func' => function_exists('exec'), 'proc_open' => function_exists('proc_open'), 'imgrepo' => $ir, 'raw_reach' => $reach, 'hint' => $gitOk ? 'git 可用,附件可走 git 推图仓' : '⚠ 服务器 git 不可用(未装 git 或 exec 被禁),附件 git 推图仓功能无法运行——需服务器装 git 并放开 PHP exec', ], 'ok');