Permalink
Browse files

Add JPG image handling to pastes. Upload base64 data of a jpeg file t…

…hen visit pasteros.io/<paste-id>.jpg to view it!
  • Loading branch information...
snacsnoc committed Aug 10, 2016
1 parent d935659 commit 393ba98e342346d5c14a4142508bb6df71af77c4
Showing with 31 additions and 0 deletions.
  1. +13 −0 controllers/View_Controller.php
  2. +18 −0 routes.php
@@ -107,7 +107,20 @@ public function get_raw($paste_id) {
header("Content-Description: File Transfer");
return $content;
}
public function get_image($paste_id, $type=jpeg) {
//Select the paste based on the ID given
$get_paste = \RedBeanPHP\R::dispense('paste');
$paste_content = $get_paste->getPaste($paste_id);
$content = base64_decode($paste_content['content']);
//Allow the user to view the raw content
header("Content-type: image/$type");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " .(string)(filesize($content)) );
return $content;
}
public function get_markdown($paste_id) {
//Select the paste based on the ID given
View
@@ -36,6 +36,24 @@
$_SESSION['delete_id'] = null;
});
//Viewing a paste with jpeg
$klein->respond('GET', '/[:id].jpg', function ($request, $response, $service) {
$paste_id = $request->id;
$paste_view = new View_Controller();
$get_image = $paste_view->get_image($paste_id);
if(strlen($paste_id) == 13){
if (false !== $get_image) {
echo $get_image;
} else {
$_SESSION['error'] = 'invalid paste number!';
return header('Location: /');
}
}
//Set our session data for the delete ID to null after displaying it once
$_SESSION['delete_id'] = null;
});
//Viewing a paste in a raw format
$klein->respond('GET', '/[:id]/raw', function ($request, $response, $service) {
$paste_id = $request->id;

0 comments on commit 393ba98

Please sign in to comment.