上传文件至 admin
This commit is contained in:
23
admin/ajax_toggle_image.php
Normal file
23
admin/ajax_toggle_image.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
require_once '../config.php';
|
||||
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['username'] !== 'admin') {
|
||||
echo json_encode(['success' => false, 'error' => '无权限']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if ($input && isset($input['image_id']) && isset($input['is_public'])) {
|
||||
try {
|
||||
$stmt = $pdo->prepare("UPDATE images SET is_public = ? WHERE id = ?");
|
||||
$stmt->execute([$input['is_public'], $input['image_id']]);
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
} catch(PDOException $e) {
|
||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||
}
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'error' => '无效请求']);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user