--- /dev/null
+<?php
+ $id = array_shift($pieces);
+
+ if (empty($id)) {
+ header('HTTP/1.0 400 Bad Request');
+ die('400 Bad (Empty) Request');
+ }
+
+ require_once __DIR__ . '/db.php';
+
+ $db = get_db();
+ $fetch_stmt = $db->prepare('SELECT
+ pi.ID, pi.MIME_TYPE, pi.PIC_B64
+ FROM pics pi
+ WHERE pi.ID = :id');
+ $fetch_stmt->bindValue(':id', $id);
+ $result = $fetch_stmt->execute();
+ if ($pic = $result->fetchArray()) {
+ $mime_type = $pic['MIME_TYPE'];
+ $file_b64 = $pic['PIC_B64'];
+ $pic_id = $pic['ID'];
+ header("Content-Type: {$mime_type}");
+ die(base64_decode($file_b64, true));
+ }
+ header('HTTP/1.0 404 Not Found');
+ die('404 File Not Found');
+?>