File tree 1 file changed +10
-4
lines changed
src/api/src/Infrastructure/Controller
1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 8
8
use Ramsey \Uuid \Uuid ;
9
9
use Symfony \Component \HttpFoundation \Response ;
10
10
11
+ use function file_exists ;
11
12
use function Safe \file_get_contents ;
12
13
use function Safe \unlink ;
13
14
14
15
abstract class DownloadXLSXController extends DownloadController
15
16
{
16
17
protected function createResponseWithXLSXAttachment (string $ filename , Xlsx $ xlsx ): Response
17
18
{
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
+ }
22
28
23
29
return $ this ->createResponseWithAttachment (
24
30
$ filename ,
You can’t perform that action at this time.
0 commit comments