Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $app->get('/images/{uuid}', function($request, $response, $args) {
- $uuid = $args['uuid'];
- /* table pictures
- `picture_id` int(11) NOT NULL AUTO_INCREMENT,
- `file_name` varchar(200) NOT NULL,
- `description` text,
- `upload_date` varchar(45) NOT NULL,
- `uuid` varchar(100) NOT NULL,
- `mime_type` varchar(45) NOT NULL,
- */
- $picture = new ITS\pictures($this->db); // 15 is the tblvehicleType tableID
- $myPicture = $picture->getPicByUuid($uuid);
- $mimeType = $myPicture['mime_type'];
- $fullPathName = $this->rootDirectory . $myPicture['file_name'];
- if ($fd = fopen ($fullPathName, "r")) {
- $size = filesize($fullPathName);
- $path_parts = pathinfo($fullPathName);
- $ext = strtolower($path_parts["extension"]);
- if (!$outputName) {
- $outputName = $path_parts["basename"];
- } else {
- if (count(explode('.', $outputName)) <= 1) {
- $outputName = $outputName . '.' . $ext;
- }
- }
- $response = $response->withHeader("Content-type", "image/png");
- $response = $response->withHeader("Content-Disposition", 'filename="' . $myPicture['file_name'] . '"');
- $response = $response->withHeader("Cache-control", "private");
- $response = $response->withHeader("Content-length", $size);
- $stream = new Stream($fd);
- $response = $response->withBody($stream);
- return $response;
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement