Ansonsten config.php und die sqlight db löschen und nochmals installieren.
Kopier mal diesen Code hier in die books.php:
Code: Alles auswählen
<?php
declare(strict_types=1);
require __DIR__ . '/db.php';
require_installed();
try {
$pdo = db();
$sql = "
SELECT
b.id,
b.title,
b.author,
b.isbn,
b.note,
b.image,
b.created_at,
CASE WHEN l.id IS NULL THEN 1 ELSE 0 END AS available,
u.name AS loaned_to,
l.loaned_at
FROM books b
LEFT JOIN loans l ON l.book_id = b.id AND l.returned_at IS NULL
LEFT JOIN users u ON u.id = l.user_id
ORDER BY b.id DESC
";
$books = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
/*
* Web-BASISPFAD sicher ermitteln
* Beispiel:
* /buch/api/books.php -> /buch
* /buch_leihe/api/books.php -> /buch_leihe
*/
$script = $_SERVER['SCRIPT_NAME'] ?? '';
$baseUrl = rtrim(dirname(dirname($script)), '/');
foreach ($books as &$b) {
if (!empty($b['image'])) {
// WICHTIG: nur Webpfad, kein Serverpfad!
$b['image_url'] = $baseUrl . '/uploads/books/' . $b['image'];
} else {
$b['image_url'] = $baseUrl . '/assets/no-cover.svg';
}
}
unset($b);
json_response([
'ok' => true,
'books' => $books
]);
} catch (Throwable $e) {
json_response([
'ok' => false,
'error' => $e->getMessage()
], 500);
}
Das scheint ein Pfadproblem. ist aber komisch das es gestern lief.
Die Bilder werden nicht gefunden weil sie nicht auf uploads/books verlinken sondern ins root
book_37c93b076c60d5b3.png:1 Failed to load resource: the server responded with a status of 404 ()
book_5287719138a77401.png:1 Failed to load resource: the server responded with a status of 404 ()
book_ac8fb138d660bd62.jpg:1 Failed to load resource: the server responded with a status of 404 ()
book_dc56fdad467f74d2.png:1 Failed to load resource: the server responded with a status of 404 ()
book_9c7fedb2973f2cca.png:1 Failed to load resource: the server responded with a status of 404 ()