-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_cover.php
More file actions
34 lines (29 loc) · 1.18 KB
/
save_cover.php
File metadata and controls
34 lines (29 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Lese die eingehenden JSON-Daten
$data = json_decode(file_get_contents('php://input'), true);
// Überprüfe, ob die coverUrl und isbn vorhanden sind
if (isset($data['coverUrl']) && isset($data['isbn'])) {
$coverUrl = $data['coverUrl'];
$isbn = $data['isbn']; // ISBN lesen
// Verwende die ISBN als Dateinamen
$imageName = $isbn . '.png';
$imagePath = 'img/' . $imageName; // Speichere im img-Ordner
// Lade das Bild von der URL
$imageContent = file_get_contents($coverUrl);
// Überprüfen, ob das Bild erfolgreich geladen wurde
if ($imageContent !== false) {
// Speichere das Bild auf dem Server
file_put_contents($imagePath, $imageContent);
// Erfolgreiche Antwort
echo json_encode(['message' => 'Cover gespeichert: ' . $imageName]);
} else {
echo json_encode(['message' => 'Fehler beim Laden des Bildes.']);
}
} else {
echo json_encode(['message' => 'Keine Bild-URL oder ISBN angegeben.']);
}
} else {
echo json_encode(['message' => 'Ungültige Anfrage.']);
}
?>