简体   繁体   中英

How to set the filename for a downloadable file in laravel?

Hi i want to rename the a file that can be downloaded from the website.

This is how i populate the response.

return response()->view('ordersxml.order-template',compact('order','debtor','today'))->header('Content-Type','text/xml')->header('Content-disposition','attachment')->header('filename','test');

The ->header('filename','test');

Is not working. What am i doing wrong?

THanks in advance

Of course, you can add header filename , but it won't work, because proper header for download is:

Content-Disposition: attachment; filename="filename.jpg"

So, you code should be:

return response()
     ->view('ordersxml.order-template',compact('order','debtor','today'))
     ->header('Content-Type','text/xml')
     ->header('Content-disposition','attachment; filename="test"'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM