ppeasy/public/delete_file.php

36 lines
1.1 KiB
PHP

<?php
include('include/headscript.php'); ?>
<?php
if (isset($_POST['fileId'])) {
$fileId = $_POST['fileId'];
// Recupera il nome del file usando l'ID dal database
// Assumi $conn come tua connessione al database
$conn = new mysqli($servername, $username, $password, $dbname);
$stmt = $conn->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()) {
// echo 'success';
} else {
echo 'database_error';
}
} else {
echo 'file_delete_error';
}
} else {
echo 'file_not_found';
}
$stmt->close();
}