From 190d6200ce76eeb4910f687b38449257eb6c19ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 23 Apr 2025 15:33:59 +0200 Subject: [PATCH] fix: adopt potentially changed file extension when downloading --- .../Administrative/Document/BatchDownloadController.php | 8 +++++++- src/Controller/Common/DownloadController.php | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Controller/Administrative/Document/BatchDownloadController.php b/src/Controller/Administrative/Document/BatchDownloadController.php index f006463..c8eb691 100644 --- a/src/Controller/Administrative/Document/BatchDownloadController.php +++ b/src/Controller/Administrative/Document/BatchDownloadController.php @@ -59,6 +59,12 @@ class BatchDownloadController extends AbstractController /** @var Upload $upload */ $filename = $upload->getOriginalFilename(); $filepath = $this->uploadHandler->getUploadFilepath($upload); + $extension = pathinfo($filepath, PATHINFO_EXTENSION); + + // adopt potentially changed file extension + if (false === str_ends_with($filename, $extension)) { + $filename = $filename.'.'.$extension; + } try { $zip->addFileFromPath(fileName: $filename, path: $filepath); @@ -79,4 +85,4 @@ class BatchDownloadController extends AbstractController return $response; } -} \ No newline at end of file +} diff --git a/src/Controller/Common/DownloadController.php b/src/Controller/Common/DownloadController.php index 0740340..f6bd29c 100644 --- a/src/Controller/Common/DownloadController.php +++ b/src/Controller/Common/DownloadController.php @@ -29,7 +29,15 @@ class DownloadController extends AbstractController public function index(Upload $upload, Request $request): Response { $path = $this->uploadHandler->getUploadFilepath($upload); + $extension = pathinfo($path, PATHINFO_EXTENSION); + + // adopt potentially changed file extension $originalFilename = $upload->getOriginalFilename(); + + if (false === str_ends_with($originalFilename, $extension)) { + $originalFilename = $originalFilename.'.'.$extension; + } + $inline = (bool) $request->get('inline'); $disposition = $inline ? ResponseHeaderBag::DISPOSITION_INLINE : ResponseHeaderBag::DISPOSITION_ATTACHMENT;