File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
src/api/src/Infrastructure/Controller Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 88use Ramsey \Uuid \Uuid ;
99use Symfony \Component \HttpFoundation \Response ;
1010
11+ use function file_exists ;
1112use function Safe \file_get_contents ;
1213use function Safe \unlink ;
1314
1415abstract class DownloadXLSXController extends DownloadController
1516{
1617 protected function createResponseWithXLSXAttachment (string $ filename , Xlsx $ xlsx ): Response
1718 {
18- $ tmpFilename = Uuid::uuid4 ()->toString () . '.xlsx ' ;
19- $ xlsx ->save ($ tmpFilename );
20- $ fileContent = file_get_contents ($ tmpFilename );
21- unlink ($ tmpFilename );
19+ try {
20+ $ tmpFilename = Uuid::uuid4 ()->toString () . '.xlsx ' ;
21+ $ xlsx ->save ($ tmpFilename );
22+ $ fileContent = file_get_contents ($ tmpFilename ); // Get the file content.
23+ } finally {
24+ if (file_exists ($ tmpFilename )) {
25+ unlink ($ tmpFilename ); // Delete the file.
26+ }
27+ }
2228
2329 return $ this ->createResponseWithAttachment (
2430 $ filename ,
You can’t perform that action at this time.
0 commit comments