From a271d239c66ed17d974387fb113ab07cfb909f1b Mon Sep 17 00:00:00 2001 From: wizardeur <57131776+wizardeur@users.noreply.github.com> Date: Fri, 1 Mar 2024 13:20:47 +0100 Subject: [PATCH] A fix for mime types handling --- app/Domain/Files/Controllers/Get.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Domain/Files/Controllers/Get.php b/app/Domain/Files/Controllers/Get.php index 93e3481a8..8e5f79f2a 100644 --- a/app/Domain/Files/Controllers/Get.php +++ b/app/Domain/Files/Controllers/Get.php @@ -81,15 +81,19 @@ private function getFileLocally($encName, $ext, $module, $realName): Response $path_parts = pathinfo($fullPath); if ($ext == 'pdf') { + $mime_type = 'application/pdf'; header('Content-type: application/pdf'); header("Content-Disposition: inline; filename=\"" . $realName . "." . $ext . "\""); } elseif ($ext == 'jpg' || $ext == 'jpeg' || $ext == 'gif' || $ext == 'png') { + $mime_type = $mimes[$ext]; header('Content-type: ' . $mimes[$ext]); header('Content-disposition: inline; filename="' . $realName . "." . $ext . '";'); } elseif ($ext == 'svg') { + $mime_type = 'image/svg+xml'; header('Content-type: image/svg+xml'); header('Content-disposition: attachment; filename="' . $realName . "." . $ext . '";'); } else { + $mime_type = 'application/octet-stream'; header("Content-type: application/octet-stream"); header("Content-Disposition: filename=\"" . $realName . "." . $ext . "\""); } @@ -102,7 +106,7 @@ private function getFileLocally($encName, $ext, $module, $realName): Response $oStreamResponse = new StreamedResponse(); - $oStreamResponse->headers->set("Content-Type", $mimes[$ext] ); + $oStreamResponse->headers->set("Content-Type", $mime_type ); $oStreamResponse->headers->set("Content-Length", $sFileSize); $oStreamResponse->headers->set("ETag", $sEtag);