]> git.agnieray.net Git - galette.git/commitdiff
Fix dynamic file display; closes #1486
authorJohan Cwiklinski <johan@x-tnd.be>
Mon, 14 Sep 2020 09:56:17 +0000 (11:56 +0200)
committerJohan Cwiklinski <johan@x-tnd.be>
Mon, 14 Sep 2020 09:56:17 +0000 (11:56 +0200)
galette/lib/Galette/Controllers/Crud/MembersController.php

index d06c587b69094875b3951076b3585b1cda9e0d8b..ab5b90be49824cbe8e640f33079d75bc018e17af 100644 (file)
@@ -475,15 +475,24 @@ class MembersController extends CrudController
 
         if (file_exists(GALETTE_FILES_PATH . $filename)) {
             $type = File::getMimeType(GALETTE_FILES_PATH . $filename);
-            $response = $response
+
+            $response = $response->withHeader('Content-Description', 'File Transfer')
                 ->withHeader('Content-Type', $type)
                 ->withHeader('Content-Disposition', 'attachment;filename="' . $args['name'] . '"')
-                ->withHeader('Pragma', 'no-cache');
-            $response->write(readfile(GALETTE_FILES_PATH . $filename));
-            return $response;
+                ->withHeader('Pragma', 'no-cache')
+                ->withHeader('Content-Transfer-Encoding', 'binary')
+                ->withHeader('Expires', '0')
+                ->withHeader('Cache-Control', 'must-revalidate')
+                ->withHeader('Pragma', 'public');
+
+            $stream = fopen('php://memory', 'r+');
+            fwrite($stream, file_get_contents(GALETTE_FILES_PATH . $filename));
+            rewind($stream);
+
+            return $response->withBody(new \Slim\Http\Stream($stream));
         } else {
             Analog::log(
-                'A request has been made to get an exported file named `' .
+                'A request has been made to get a dynamic file named `' .
                 $filename . '` that does not exists.',
                 Analog::WARNING
             );