aboutsummaryrefslogtreecommitdiff
path: root/src/Handlers/AttachmentHandler.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Handlers/AttachmentHandler.php')
-rw-r--r--src/Handlers/AttachmentHandler.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/Handlers/AttachmentHandler.php b/src/Handlers/AttachmentHandler.php
new file mode 100644
index 0000000..9b329b0
--- /dev/null
+++ b/src/Handlers/AttachmentHandler.php
@@ -0,0 +1,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()));
+ }
+} \ No newline at end of file