Files
Sistema-Web-Rotiseria/admin/descargar_file.php
T
2026-06-30 15:01:01 -03:00

34 lines
992 B
PHP

<?php
include("../db.php");
if (!isset($_SESSION['rol']) || $_SESSION['rol'] !== 'admin') {
header("Location: ../login.php?error=acceso_denegado");
exit();
}
if (isset($_GET['file'])) {
$archivo = basename($_GET['file']);
$ruta_completa = "backups_files/" . $archivo;
if (file_exists($ruta_completa)) {
// MEJORA: Limpia y deshabilita los buffers de salida para evitar corromper el ZIP
if (ob_get_level()) {
ob_end_clean();
}
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $archivo . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($ruta_completa));
flush();
readfile($ruta_completa);
exit();
} else {
echo "El archivo no existe.";
}
}
?>