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;
1616
1717protected function createResponseWithXLSXAttachment(string $filename, Xlsx $xlsx): Response
1818{
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+
2429 return $this->createResponseWithAttachment(
2530 $filename,
2631 $fileContent
2732 );
2833}
29- ```
34+ ```
You can’t perform that action at this time.
0 commit comments