prepare($getAppSql); $stmt->bind_param("i", $appId); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows === 0) { header('Location: index.php?error=App不存在'); exit; } $app = $result->fetch_assoc(); $platforms = json_decode($app['platforms'], true); $success = ''; $error = ''; // 处理编辑App请求 if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['edit_app'])) { $name = $_POST['name']; $description = $_POST['description']; $ageRating = $_POST['age_rating']; $newPlatforms = json_encode($_POST['platforms'] ?? []); // 处理表单提交 if ($_SERVER['REQUEST_METHOD'] === 'POST') { // 验证必填字段 $required = ['name', 'description', 'age_rating', 'platforms']; $errors = []; foreach ($required as $field) { if (empty($_POST[$field])) { $errors[] = ucfirst($field) . ' 不能为空'; } } // 年龄分级验证 if (($_POST['age_rating'] === '12+' || $_POST['age_rating'] === '17+') && empty($_POST['age_rating_description'])) { $errors[] = '年龄分级为12+或以上时,年龄分级说明不能为空'; } // 处理应用图标上传(如果有新上传) if (!empty($_FILES['images']['name'][0])) { $uploadDir = '../images/'; foreach ($_FILES['images']['tmp_name'] as $key => $tmpName) { $fileName = basename($_FILES['images']['name'][$key]); $targetPath = $uploadDir . $fileName; if (move_uploaded_file($tmpName, $targetPath)) { $insertImageSql = "INSERT INTO app_images (app_id, image_path) VALUES (?, ?)"; $imgStmt = $conn->prepare($insertImageSql); $imgStmt->bind_param("is", $appId, $targetPath); $imgStmt->execute(); } } } // 处理新上传的App文件 if (!empty($_FILES['app_file']['name'])) { $uploadDir = '../files/'; $fileName = basename($_FILES['app_file']['name']); $targetPath = $uploadDir . $fileName; if (move_uploaded_file($_FILES['app_file']['tmp_name'], $targetPath)) { $version = $_POST['version']; $changelog = $_POST['changelog']; $insertVersionSql = "INSERT INTO app_versions (app_id, version, changelog, file_path) VALUES (?, ?, ?, ?)"; $verStmt = $conn->prepare($insertVersionSql); $verStmt->bind_param("isss", $appId, $version, $changelog, $targetPath); $verStmt->execute(); } } header('Location: index.php?success=App 更新成功'); exit; } else { $error = 'App 更新失败: '. $conn->error; } } ?>