aboutsummaryrefslogtreecommitdiff
path: root/src/Handlers/AttachmentHandler.php
blob: 9b329b020533147f7da4e817f1c7bc0543254d80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php


namespace Micropoly\Handlers;


use Micropoly\Env;
use Micropoly\Handler;
use Micropoly\Models\Attachment;

class AttachmentHandler implements Handler
{
    public function handle(\Micropoly\Env $env, array $variables)
    {
        $db = $env->db();

        $attachment = Attachment::byId($db, $variables["id"]);
        if ($attachment === null) {
            (new NotFoundHandler())->handle($env, []);
            return;
        }

        header("Content-Type: {$attachment->getMime()}");
        readfile($attachment->getFilePath($env->attachmentsPath()));
    }
}