File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -16,14 +16,19 @@ use function Safe\unlink;
16
16
17
17
protected function createResponseWithXLSXAttachment(string $filename, Xlsx $xlsx): Response
18
18
{
19
- $tmpFilename = Uuid::uuid4()->toString() . '.xlsx';
20
- $xlsx->save($tmpFilename);
21
- $fileContent = file_get_contents($tmpFilename); // Get the file content.
22
- unlink($tmpFilename); // Delete the file.
23
-
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
+ }
28
+
24
29
return $this->createResponseWithAttachment(
25
30
$filename,
26
31
$fileContent
27
32
);
28
33
}
29
- ```
34
+ ```
You can’t perform that action at this time.
0 commit comments