added files for mescole
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
include('include/headscript.php');
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$id = isset($_POST['id']) ? (int)$_POST['id'] : 0;
|
||||
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['success' => false, 'message' => 'ID non valido']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$stmt = $pdo->prepare("SELECT idmescola, filename FROM mescole_files WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$row) {
|
||||
echo json_encode(['success' => false, 'message' => 'File non trovato']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$del = $pdo->prepare("DELETE FROM mescole_files WHERE id = ?");
|
||||
$del->execute([$id]);
|
||||
|
||||
$path = __DIR__ . '/uploads/mescole/' . $row['idmescola'] . '/' . $row['filename'];
|
||||
if (is_file($path)) {
|
||||
@unlink($path);
|
||||
}
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
} catch (Throwable $e) {
|
||||
echo json_encode(['success' => false, 'message' => 'Errore database: ' . $e->getMessage()]);
|
||||
}
|
||||
Reference in New Issue
Block a user