' . htmlspecialchars($newFileName); } else { echo '文件重命名失败!'; } } else { echo '文件重命名失败,文件不存在或新文件名已存在。'; } } if (isset($_POST['saveContent'], $_POST['fileName'], $_POST['fileType'])) { $fileToSave = ($_POST['fileType'] === 'proxy') ? $uploadDir . basename($_POST['fileName']) : $configDir . basename($_POST['fileName']); $contentToSave = $_POST['saveContent']; file_put_contents($fileToSave, $contentToSave); echo '
文件内容已更新:' . htmlspecialchars(basename($fileToSave)) . '
'; } } function formatFileModificationTime($filePath) { if (file_exists($filePath)) { $fileModTime = filemtime($filePath); return date('Y-m-d H:i:s', $fileModTime); } else { return '文件不存在'; } } $proxyFiles = scandir($uploadDir); $configFiles = scandir($configDir); if ($proxyFiles !== false) { $proxyFiles = array_diff($proxyFiles, array('.', '..')); } else { $proxyFiles = []; } if ($configFiles !== false) { $configFiles = array_diff($configFiles, array('.', '..')); } else { $configFiles = []; } function formatSize($size) { $units = array('B', 'KB', 'MB', 'GB', 'TB'); $unit = 0; while ($size >= 1024 && $unit < count($units) - 1) { $size /= 1024; $unit++; } return round($size, 2) . ' ' . $units[$unit]; } if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['editFile'], $_GET['fileType'])) { $filePath = ($_GET['fileType'] === 'proxy') ? $uploadDir. basename($_GET['editFile']) : $configDir . basename($_GET['editFile']); if (file_exists($filePath)) { header('Content-Type: text/plain'); echo file_get_contents($filePath); exit; } else { echo '文件不存在'; exit; } } ?> '', 'file_name' => "subscription_" . ($i + 1) . ".yaml", ]; } } if (isset($_POST['update'])) { $index = intval($_POST['index']); $url = $_POST['subscription_url'] ?? ''; $customFileName = $_POST['custom_file_name'] ?? "subscription_" . ($index + 1) . ".yaml"; $subscriptions[$index]['url'] = $url; $subscriptions[$index]['file_name'] = $customFileName; if (!empty($url)) { $finalPath = $subscriptionPath . $customFileName; $command = "wget -q --show-progress -O {$finalPath} {$url}"; exec($command . ' 2>&1', $output, $return_var); if ($return_var !== 0) { $command = "curl -s -o {$finalPath} {$url}"; exec($command . ' 2>&1', $output, $return_var); } if ($return_var === 0) { $_SESSION['update_messages'] = array(); $_SESSION['update_messages'][] = '