34 lines
975 B
PHP
34 lines
975 B
PHP
<?php
|
|
require_once(__DIR__ . '/class/db-functions.php');
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
$id = intval($_POST['id'] ?? 0);
|
|
if ($id <= 0) {
|
|
echo json_encode(['status' => 'error', 'message' => 'Invalid file ID']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
// Recupera il nome del file
|
|
$stmt = $pdo->prepare("SELECT filename FROM client_files WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($row && !empty($row['filename'])) {
|
|
$filePath = __DIR__ . '/../uploads/client_files/' . $row['filename'];
|
|
if (file_exists($filePath)) {
|
|
unlink($filePath); // elimina file fisico
|
|
}
|
|
}
|
|
|
|
// Cancella riga dal DB
|
|
$pdo->prepare("DELETE FROM client_files WHERE id = ?")->execute([$id]);
|
|
|
|
echo json_encode(['status' => 'ok']);
|
|
} catch (Exception $e) {
|
|
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
|
}
|