query('SELECT id, name FROM tags'); while ($tag = $tagStmt->fetch_assoc()) { $tags[] = $tag; } $tagStmt->close(); // 获取应用现有标签 $appTags = []; $appTagStmt = $conn->prepare('SELECT tag_id FROM app_tags WHERE app_id = ?'); $appTagStmt->bind_param('i', $appId); $appTagStmt->execute(); $appTagResult = $appTagStmt->get_result(); while ($tag = $appTagResult->fetch_assoc()) { $appTags[] = $tag['tag_id']; } $appTagStmt->close(); // 获取应用信息并验证开发者权限 $stmt = $conn->prepare('SELECT id, name, description, version, changelog, age_rating, age_rating_description, platforms, file_path FROM apps WHERE id = ? AND developer_id = ?'); if (!$stmt) { log_error('获取应用信息查询准备失败: ' . $conn->error, __FILE__, __LINE__); $error = '获取应用信息时发生错误,请稍后再试'; header('Location: dashboard.php'); exit; } $stmt->bind_param('ii', $appId, $developerId); if (!$stmt->execute()) { log_error('获取应用信息查询执行失败: ' . $stmt->error, __FILE__, __LINE__); $error = '获取应用信息时发生错误,请稍后再试'; header('Location: dashboard.php'); exit; } $result = $stmt->get_result(); $app = $result->fetch_assoc(); if (!$app) { header('Location: dashboard.php'); exit; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $appName = trim($_POST['name']); $appDescription = trim($_POST['description']); $version = trim($_POST['version']); $changelog = trim($_POST['changelog']); $ageRating = $_POST['age_rating']; $ageRatingDescription = trim($_POST['age_rating_description']); $platforms = $_POST['platforms'] ?? []; $platforms_json = json_encode($platforms); $appFilePath = $app['file_path']; // 默认使用现有文件路径 // 获取选中的标签 $selectedTags = $_POST['tags'] ?? []; // 处理应用文件上传 if (!empty($_FILES['app_file']['tmp_name'])) { $uploadDir = '../uploads/apps/'; $fileExtension = pathinfo($_FILES['app_file']['name'], PATHINFO_EXTENSION); $newFileName = uniqid() . '.' . $fileExtension; $targetPath = $uploadDir . $newFileName; // 验证文件类型和大小 $allowedTypes = ['apk', 'exe', 'jar', 'crx', 'ini']; if (!in_array($fileExtension, $allowedTypes)) { $error = '不支持的文件类型,请上传 ' . implode(', ', $allowedTypes) . ' 格式的文件'; } elseif ($_FILES['app_file']['size'] > 50 * 1024 * 1024) { // 50MB $error = '文件大小不能超过50MB'; } elseif (!move_uploaded_file($_FILES['app_file']['tmp_name'], $targetPath)) { $error = '文件上传失败,请检查服务器权限'; } else { // 删除旧文件 if (file_exists($appFilePath)) { unlink($appFilePath); } $appFilePath = $targetPath; } } // 处理图片删除 if (!empty($_POST['removed_images'])) { $removedImageIds = explode(',', $_POST['removed_images']); foreach ($removedImageIds as $imgId) { if (is_numeric($imgId)) { // 获取图片路径 $stmt = $conn->prepare("SELECT image_path FROM app_images WHERE id = ?"); $stmt->bind_param("i", $imgId); $stmt->execute(); $imgResult = $stmt->get_result(); if ($img = $imgResult->fetch_assoc()) { // 删除文件 if (file_exists($img['image_path'])) { unlink($img['image_path']); } // 删除数据库记录 $deleteStmt = $conn->prepare("DELETE FROM app_images WHERE id = ?"); $deleteStmt->bind_param("i", $imgId); $deleteStmt->execute(); $deleteStmt->close(); } $stmt->close(); } } } // 更新应用标签 // 删除现有标签关联 $deleteTagStmt = $conn->prepare('DELETE FROM app_tags WHERE app_id = ?'); $deleteTagStmt->bind_param('i', $appId); $deleteTagStmt->execute(); $deleteTagStmt->close(); // 添加新标签关联 foreach ($selectedTags as $tagId) { if (is_numeric($tagId)) { $tagStmt = $conn->prepare('INSERT INTO app_tags (app_id, tag_id) VALUES (?, ?)'); $tagStmt->bind_param('ii', $appId, $tagId); $tagStmt->execute(); $tagStmt->close(); } } // 处理新图片上传 $imageUploadDir = '../uploads/images/'; $allowedImageTypes = ['jpg', 'jpeg', 'png']; $maxImages = 5; $currentImageCount = count($existingImages) - count($removedImageIds ?? []); if (!empty($_FILES['images']['name'][0]) && empty($error)) { $newImages = $_FILES['images']; for ($i = 0; $i < count($newImages['name']); $i++) { if ($newImages['error'][$i] !== UPLOAD_ERR_OK) continue; $fileName = $newImages['name'][$i]; $fileTmp = $newImages['tmp_name'][$i]; $fileSize = $newImages['size'][$i]; $fileExt = strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); if (!in_array($fileExt, $allowedImageTypes)) { $error = "图片 {$fileName} 格式不支持,仅允许jpg、png"; break; } if ($fileSize > 2 * 1024 * 1024) { // 2MB $error = "图片 {$fileName} 大小超过2MB"; break; } if ($currentImageCount >= $maxImages) { $error = "最多只能上传5张图片"; break; } $newFileName = uniqid() . '.' . $fileExt; $targetPath = $imageUploadDir . $newFileName; if (move_uploaded_file($fileTmp, $targetPath)) { // 插入数据库 $stmt = $conn->prepare("INSERT INTO app_images (app_id, image_path) VALUES (?, ?)"); $stmt->bind_param("is", $appId, $targetPath); $stmt->execute(); $stmt->close(); $currentImageCount++; } else { $error = "图片 {$fileName} 上传失败"; break; } } } // 验证标签选择 if (empty($selectedTags)) { $error = '至少需要选择一个应用标签'; } if (empty($appName) || empty($appDescription) || empty($version) || empty($changelog) || empty($ageRating) || empty($ageRatingDescription)) { $error = '应用名称和描述不能为空'; } else { // 检查数据库连接是否为 MySQLi 对象 if (!($conn instanceof mysqli)) { log_error('数据库连接错误: 连接不是MySQLi实例', __FILE__, __LINE__); $error = '数据库连接错误,请检查配置'; } else { $platforms = $_POST['platforms'] ?? []; $platforms_json = json_encode($platforms); $stmt = $conn->prepare('UPDATE apps SET name = ?, description = ?, version = ?, changelog = ?, age_rating = ?, age_rating_description = ?, platforms = ?, file_path = ?, status = \'pending\' WHERE id = ? AND developer_id = ?'); if (!$stmt) { log_error('更新应用信息查询准备失败: ' . $conn->error, __FILE__, __LINE__); $error = '更新应用信息时发生错误,请稍后再试'; } else { $stmt->bind_param('ssssssssii', $appName, $appDescription, $version, $changelog, $ageRating, $ageRatingDescription, $platforms_json, $appFilePath, $appId, $developerId); if (!$stmt->execute()) { log_error('更新应用信息查询执行失败: ' . $stmt->error, __FILE__, __LINE__); $error = '更新应用信息时发生错误,请稍后再试'; } else { $success = '应用信息更新成功,请等待管理员重新审核'; header('Location: dashboard.php?success=' . urlencode($success)); exit; $app['name'] = $appName; $app['description'] = $appDescription; } } } } } ?> 编辑应用

编辑应用

>
>
>
>
>
>
>
>
>
>
按住Ctrl键可选择多个标签
当前文件:
prepare("SELECT id, image_path FROM app_images WHERE app_id = ?"); $stmt->bind_param("i", $appId); $stmt->execute(); $imgResult = $stmt->get_result(); while ($img = $imgResult->fetch_assoc()) { $existingImages[] = $img; } $stmt->close(); ?>
应用图片
支持jpg、png格式,最多上传5张图片
返回仪表盘