38 lines
1013 B
PHP
38 lines
1013 B
PHP
<?php
|
|
// delete_photo.php
|
|
include('include/headscript.php');
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['photo_id'])) {
|
|
echo json_encode(['success' => false, 'message' => 'Richiesta non valida']);
|
|
exit;
|
|
}
|
|
|
|
$photoId = intval($_POST['photo_id']);
|
|
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
// Recupera il percorso del file
|
|
$stmt = $pdo->prepare("SELECT file_path FROM datadb_photos WHERE id = ?");
|
|
$stmt->execute([$photoId]);
|
|
$photo = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$photo) {
|
|
echo json_encode(['success' => false, 'message' => 'Foto non trovata']);
|
|
exit;
|
|
}
|
|
|
|
// Elimina il file dal server
|
|
$filePath = '../photostrf/' . $photo['file_path'];
|
|
if (file_exists($filePath)) {
|
|
unlink($filePath);
|
|
}
|
|
|
|
// Elimina il record dal database
|
|
$stmt = $pdo->prepare("DELETE FROM datadb_photos WHERE id = ?");
|
|
$stmt->execute([$photoId]);
|
|
|
|
echo json_encode(['success' => true, 'message' => 'Foto eliminata con successo']);
|