Skip to content
Advertisement

Assign filename dynamically in a response

in my web application created with Laravel 8, I need to download an .xml file and the file name must be dynamically created, as per the title. this is because the file name is composed following a specific rule and having to include today’s date.

$filename = 'FirstPart_'.date("Y-m-d").'_000.xml'

so far to test the response and therefore the download I have given a fixed name to the file, as follows, and the download is performed correctly.

  • code with fixed filename
JavaScript

But when i try to download the file with my custom filename, the download fails.

  • code with custom filename
JavaScript

I appreciate any suggestion or advice

Advertisement

Answer

Your code have a error in this line, In this case “$filename” append in your header not dynamic file name value.

JavaScript

try this solution:

JavaScript

Append $filename in your filename that pass tp $response->header.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement