1 | <?php |
2 | |
3 | require_once __DIR__ . "/../lib/php/ejecutaServicio.php"; |
4 | require_once __DIR__ . "/../lib/php/pdFaltaId.php"; |
5 | require_once __DIR__ . "/../lib/php/ProblemDetails.php"; |
6 | require_once __DIR__ . "/../lib/php/leeEntero.php"; |
7 | require_once __DIR__ . "/bd/archivoBusca.php"; |
8 | |
9 | mb_internal_encoding("UTF-8"); |
10 | try { |
11 | |
12 | header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); |
13 | header("Cache-Control: post-check=0, pre-check=0", false); |
14 | header("Pragma: no-cache"); |
15 | $id = leeEntero("id"); |
16 | if ($id === null) throw pdFaltaId(); |
17 | $archivo = archivoBusca($id); |
18 | if ($archivo === false) { |
19 | throw new ProblemDetails( |
20 | status: ProblemDetails::BadRequest, |
21 | type: "/error/archivonoencontrado.html", |
22 | title: "Archivo no encontrado.", |
23 | detail: "No se encontró ningún archivo con el id solicitado." |
24 | ); |
25 | } |
26 | echo $archivo->bytes; |
27 | } catch (ProblemDetails $details) { |
28 | procesa_problem_details($details); |
29 | } catch (Throwable $throwable) { |
30 | procesa_problem_details(new ProblemDetails( |
31 | status: ProblemDetails::InternalServerError, |
32 | type: "/error/errorinterno.html", |
33 | title: "Error interno del servidor.", |
34 | detail: $throwable->getMessage() |
35 | )); |
36 | } |
37 | |