isAuthenticated()) { echo json_encode(['success' => false, 'error' => 'Server nicht mit Google verbunden.']); exit; } // 2. Daten empfangen $input = json_decode(file_get_contents('php://input'), true); if (!isset($input['image']) || !isset($input['name'])) { echo json_encode(['success' => false, 'error' => 'Keine Bilddaten empfangen.']); exit; } // 3. Base64 bereinigen (Das "data:image/png;base64," entfernen) $imgParts = explode(',', $input['image']); $base64Data = end($imgParts); $binaryImage = base64_decode($base64Data); if (!$binaryImage) { echo json_encode(['success' => false, 'error' => 'Bild konnte nicht verarbeitet werden.']); exit; } // 4. Beschreibung bauen $desc = "🦖 " . $input['name'] . "\n" . "💡 " . ($input['fun_fact'] ?? '') . "\n" . "📅 " . ($input['years'] ?? ''); // 5. Hochladen $result = $google->uploadImage($binaryImage, $desc); if (isset($result['newMediaItemsResult'])) { // Google Success Structure echo json_encode(['success' => true]); } else { echo json_encode(['success' => false, 'error' => 'Google Fehler', 'details' => $result]); } ?>