<?php
require_once __DIR__.'/../../config/auth.php';require_once __DIR__.'/_comun.php';$id=(int)($_GET['id']??0);
$s=$conn->prepare('SELECT * FROM informes_avisos_documentos WHERE id=?');$s->bind_param('i',$id);$s->execute();$d=$s->get_result()->fetch_assoc();
if(!$d||!tiene_permiso_menu($conn,informes_clave($d['tipo']))){http_response_code(404);exit('Documento no disponible.');}
$ruta=dirname(__DIR__,2).'/uploads/informes_avisos/'.$d['nombre_archivo'];if(!is_file($ruta)){http_response_code(404);exit('Archivo no encontrado.');}
header('Content-Type: '.($d['mime']?:'application/octet-stream'));header('Content-Length: '.filesize($ruta));header('Content-Disposition: attachment; filename="'.str_replace(['"',"\r","\n"],'',$d['nombre_original']).'"');readfile($ruta);exit;
