0

I am generating a XLSX file using PhpSpreadSheet and downloading it successfully by visiting a specific route like this:

$writer = new Xlsx($spreadsheet);
$writer->save('TTD-HMO-ARSUB.xlsx');
return response()->download('TTD-HMO-ARSUB.xlsx');

I see that the TTD-HMO-ARSUB.xlsx file gets stored in my Laravel project's public folder.

The problem here is that I need to send some data from an Angular app through a POST request and include that data on the Excel file, so I can't just visit that route. So I decided to try to get an download URL for the file created. I have tried with these urls with no success, only 404s:

http://eiba.com/public/index.php/TTD-HMO-ARSUB.xlsx

http://eiba.com/public/TTD-HMO-ARSUB.xlsx

http://eiba.com/TTD-HMO-ARSUB.xlsx

Is there a way to access this file from a URL? Do I need to store it on another location, how?

Community
  • 1
  • 1
Multitut
  • 2,089
  • 7
  • 39
  • 63

1 Answers1

0

I solved it this way, it might not be the best one though:

$writer = new Xlsx($spreadsheet);
$writer->save('excel/TTD-HMO-ARSUB.xlsx');
return response()->json([
   'url' => 'excel/TTD-HMO-ARSUB.xlsx'
]);

It turns out you can not reference a file that is directly under the public directory, but you can use a subdirectory, like this: public/excel and a url like this will work:

http://eiba.com/excel/TTD-HMO-ARSUB.xlsx

Multitut
  • 2,089
  • 7
  • 39
  • 63