add book cover

This commit is contained in:
2025-11-20 17:16:17 +08:00
parent 6517cb2bac
commit 6a156d1444
17 changed files with 268 additions and 1602 deletions
+21
View File
@@ -120,5 +120,26 @@ class Book {
$stmt->execute([$book_id]);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
public function updateCover($book_id, $filename) {
$stmt = $this->pdo->prepare("UPDATE books SET cover_image = ? WHERE id = ?");
return $stmt->execute([$filename, $book_id]);
}
public function deleteCover($book_id) {
// Сначала получаем текущее имя файла
$book = $this->findById($book_id);
$old_filename = $book['cover_image'];
if ($old_filename) {
$file_path = COVERS_PATH . $old_filename;
if (file_exists($file_path)) {
unlink($file_path);
}
}
$stmt = $this->pdo->prepare("UPDATE books SET cover_image = NULL WHERE id = ?");
return $stmt->execute([$book_id]);
}
}
?>