| 1 | <?php |
| 2 | |
| 3 | require_once __DIR__ . "/../lib/php/NOT_FOUND.php"; |
| 4 | require_once __DIR__ . "/../lib/php/ejecutaServicio.php"; |
| 5 | require_once __DIR__ . "/../lib/php/recuperaIdEntero.php"; |
| 6 | require_once __DIR__ . "/../lib/php/ProblemDetails.php"; |
| 7 | require_once __DIR__ . "/../lib/php/selectFirst.php"; |
| 8 | require_once __DIR__ . "/Bd.php"; |
| 9 | require_once __DIR__ . "/TABLA_ARCHIVO.php"; |
| 10 | |
| 11 | ejecutaServicio(function () { |
| 12 | |
| 13 | |
| 14 | header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); |
| 15 | header("Cache-Control: post-check=0, pre-check=0", false); |
| 16 | header("Pragma: no-cache"); |
| 17 | |
| 18 | $archId = recuperaIdEntero("id"); |
| 19 | |
| 20 | $archivo = |
| 21 | selectFirst(pdo: Bd::pdo(), from: ARCHIVO, where: [ARCH_ID => $archId]); |
| 22 | |
| 23 | if ($archivo === false) { |
| 24 | $idHtml = htmlentities($archId); |
| 25 | throw new ProblemDetails( |
| 26 | status: NOT_FOUND, |
| 27 | title: "Archivo no encontrado.", |
| 28 | type: "/error/archivonoencontrado.html", |
| 29 | detail: "No se encontró ningún archivo con el id $idHtml.", |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | $bytes = $archivo[ARCH_BYTES]; |
| 34 | $contentType = (new finfo(FILEINFO_MIME_TYPE))->buffer($bytes); |
| 35 | header("Content-Type: $contentType"); |
| 36 | echo $bytes; |
| 37 | }); |
| 38 | |