zibo-dashboard/public/userarea/get_photos.php
2025-11-22 13:35:12 +01:00

39 lines
1020 B
PHP

<?php
header('Content-Type: application/json');
require_once __DIR__ . '/class/db-functions.php';
try {
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
$production_id = isset($_GET['production_id']) ? (int)$_GET['production_id'] : 0;
$photo_type = $_GET['photo_type'] ?? '';
if ($production_id <= 0 || $photo_type === '') {
throw new Exception("Parametri non validi");
}
$stmt = $pdo->prepare("
SELECT id, filename, photo_type, created_at, elaborato
FROM production_photos
WHERE production_id = :prod AND photo_type = :ptype
ORDER BY created_at DESC, id DESC
");
$stmt->execute([
':prod' => $production_id,
':ptype' => $photo_type
]);
$photos = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode([
'success' => true,
'photos' => $photos
]);
} catch (Exception $e) {
echo json_encode([
'success' => false,
'message' => $e->getMessage()
]);
}