Advertisement
Guest User

Untitled

a guest
Apr 6th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.48 KB | None | 0 0
  1. $app->get('/images/{uuid}', function($request, $response, $args) {
  2.            
  3.         $uuid = $args['uuid'];
  4.         /* table pictures
  5.           `picture_id` int(11) NOT NULL AUTO_INCREMENT,
  6.           `file_name` varchar(200) NOT NULL,
  7.           `description` text,
  8.           `upload_date` varchar(45) NOT NULL,
  9.           `uuid` varchar(100) NOT NULL,
  10.           `mime_type` varchar(45) NOT NULL,
  11.          */
  12.  
  13.         $picture = new  ITS\pictures($this->db); // 15 is the tblvehicleType tableID
  14.         $myPicture =  $picture->getPicByUuid($uuid);
  15.         $mimeType = $myPicture['mime_type'];
  16.         $fullPathName = $this->rootDirectory . $myPicture['file_name'];
  17.     if ($fd = fopen ($fullPathName, "r")) {
  18.         $size = filesize($fullPathName);
  19.         $path_parts = pathinfo($fullPathName);
  20.         $ext = strtolower($path_parts["extension"]);
  21.         if (!$outputName) {
  22.             $outputName = $path_parts["basename"];
  23.         } else {
  24.             if (count(explode('.', $outputName)) <= 1) {
  25.                 $outputName = $outputName . '.' . $ext;
  26.             }
  27.         }
  28.         $response = $response->withHeader("Content-type", "image/png");
  29.         $response = $response->withHeader("Content-Disposition", 'filename="' . $myPicture['file_name'] . '"');
  30.         $response = $response->withHeader("Cache-control", "private");
  31.         $response = $response->withHeader("Content-length", $size);
  32.         $stream = new Stream($fd);
  33.         $response = $response->withBody($stream);
  34.  
  35.         return $response;
  36.     }
  37.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement