From fd25bf8779a37e731732f3978f5cef80704f00f9 Mon Sep 17 00:00:00 2001 From: Jacob Casper Date: Sun, 26 Jun 2022 15:20:30 -0500 Subject: [PATCH] Render pictures at a canonical URL Spit out the full quality images when requested at their exact URL. This allows use as a img src element or canonical url for the RSS enclosure element to download. --- index.php | 3 +++ pic.php | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 pic.php diff --git a/index.php b/index.php index c7b91bc..b5b343e 100644 --- a/index.php +++ b/index.php @@ -18,6 +18,9 @@ switch ($path) { case '': require './app.php'; break; + case 'pic': + require './pic.php'; + break; case 'upload': require './upload.php'; break; diff --git a/pic.php b/pic.php new file mode 100644 index 0000000..ece33b9 --- /dev/null +++ b/pic.php @@ -0,0 +1,27 @@ +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'); +?> -- 2.20.1