I am trying to delete a file that is stored on my server, but the following warning occurs:
Notice: Undefined variable: path_pdf in C: \ xampp \ htdocs \ repositoryApp \ appRegisterEvents \ mainApp \ deleteFile.php on line 8
Warning: unlink (../ Uploads / Files /): Permission denied in C: \ xampp \ htdocs \ repositoryApp \ appRegisterEvents \ mainApp \ deleteFile.php on line 8
Notice: Undefined variable: path_pdf in C: \ xampp \ htdocs \ repositoryApp \ appRegisterEvents \ mainApp \ deleteFile.php on line 9 The file could not be deleted:
I am running the function as follows:
<a class="btn btn-danger btn-sm glyphicon glyphicon-remove"
ng-href="mainApp/deleteFile.php">
</a>
As it is a single file per user, I then need to look up the file name to locate it and be able to delete it with the function unlink()
but the warning returns and it does not erase the specified file.
<?php
session_start();
$id_empresa = $_SESSION['usuario']['id_empresa'];
require 'conexion.php';
$selectFile = $mysqli->query("SELECT ruta_pdf FROM empresa WHERE id_empresa=".$id_empresa.";");
if (!unlink("../Uploads/Files/".$ruta_pdf['ruta_pdf'])) {
echo "No se pudo borrar el fichero: ".$ruta_pdf['ruta_pdf'];
}
else {
echo "El fichero ".$ruta_pdf['ruta_pdf']." ha sido eliminado";
}
$updateFile = "UPDATE empresa
SET ruta_pdf = ''
WHERE 'empresa'.'id_empresa' = '$id_empresa'";
if(mysqli_query($mysqli, $updateFile))
{
echo "Datos actualizados correctamente";
header("Location: ../");
}
else
{
echo "Error al actualizar: " . $mysqli->error;
}
?>