From 43301ede147a365a00c5a3632656a72d09293c84 Mon Sep 17 00:00:00 2001 From: Pavel Stratil Date: Wed, 17 Jan 2024 00:27:06 +0000 Subject: [PATCH] Fix on file get --- glued/Controllers/ServiceController.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/glued/Controllers/ServiceController.php b/glued/Controllers/ServiceController.php index f849557..b66eb94 100644 --- a/glued/Controllers/ServiceController.php +++ b/glued/Controllers/ServiceController.php @@ -877,14 +877,13 @@ public function links_r1(Request $request, Response $response, array $args = []) if (file_exists($file)) { $mime = mime_content_type($file); - $fileStream = fopen($file, 'rb'); - $stream = (new Psr17Factory())->createStreamFromResource($fileStream); - $response = $response ->withHeader('Content-Type', $mime) ->withHeader('Content-Disposition', "attachment;filename=\"{$res['obj']}.{$mime}\"") ->withHeader('Content-Length', filesize($file)); - $response->getBody()->write($stream->getContents()); + $fileStream = fopen($file, 'rb'); + $stream = (new Psr17Factory())->createStreamFromResource($fileStream); + $response = $response->withBody($stream); return $response; } else { $data['status'] = 'Not found'; return $response->withJson($data)->withStatus(404); } }