prepare("SELECT filename_fileattached FROM tdfileattached WHERE idtdfileattached = ?"); $stmt->bind_param("i", $fileId); $stmt->execute(); $result = $stmt->get_result(); if ($row = $result->fetch_assoc()) { $filePath = 'uploadtddocuments/' . $row['filename_fileattached']; // Cancella il file dal filesystem if (unlink($filePath)) { // File cancellato, ora rimuovi il record dal database $stmt = $conn->prepare("DELETE FROM tdfileattached WHERE idtdfileattached = ?"); $stmt->bind_param("i", $fileId); if ($stmt->execute()) { // Success, reindirizza header("Location: techdossier_start.php?idtd=" . $idtd . "&idtrf=" . $idtrf); exit(); } else { echo 'database_error'; } } else { echo 'file_delete_error'; } } else { echo 'file_not_found'; } $stmt->close(); $conn->close(); // Chiudi la connessione } } } ?>