'laravel download response filename not changing
I am using laravel and trying to download a file and change the filename. The documentation tells me that I can use the second argument as the new filename, but the filename won't change to "testdownload.zip" somehow. What am I doing wrong?
https://laravel.com/docs/5.8/responses#file-downloads
// routes
Route::group(['middleware' => ['web']], function()
{
Route::group(['namespace' => 'App\Http\Controllers'], function()
{
Route::group(['middleware' => ['role:root|admin|store|user']],
function()
{
// download purchase
Route::get('dashboard/order/downloadfile', [
'as' => 'order-download',
'uses' => 'Post\PostController@download'
]);
});
}
}
// method in Controller
public function download(Request $request)
{
return response()->download(storage_path('app/lorem-ipsum-shop-1.zip'), 'testdownload.zip', ['Content-Type: application/zip']);
}
When I do dd(response()->download(storage_path('app/lorem-ipsum-shop-1.zip'), 'testdownload.zip', ['Content-Type: application/zip'])) the following is returned (could it be the perms / permissions 0100666? I am on Windows):
BinaryFileResponse {#449 ▼
#file: File {#464 ▼
path: "C:\xampp71\htdocs\storage\app"
filename: "lorem-ipsum-shop-1.zip"
basename: "lorem-ipsum-shop-1.zip"
pathname: "C:\xampp71\htdocs\storage\app/lorem-ipsum-shop-1.zip"
extension: "zip"
realPath: "C:\xampp71\htdocs\storage\app\lorem-ipsum-shop-1.zip"
aTime: 2019-11-14 11:34:52
mTime: 2019-11-14 11:34:52
cTime: 2019-11-01 16:05:10
inode: 0
size: 24626
perms: 0100666
owner: 0
group: 0
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
linkTarget: "C:\xampp71\htdocs\storage\app\lorem-ipsum-shop-1.zip"
}
#offset: 0
#maxlen: -1
#deleteFileAfterSend: false
+headers: ResponseHeaderBag {#234 ▼
#computedCacheControl: array:1 [▼
"public" => true
]
#cookies: []
#headerNames: array:5 [▼
0 => 0
"cache-control" => "Cache-Control"
"date" => "Date"
"last-modified" => "Last-Modified"
"content-disposition" => "Content-Disposition"
]
#headers: array:5 [▼
0 => array:1 [▶]
"cache-control" => array:1 [▶]
"date" => array:1 [▶]
"last-modified" => array:1 [▶]
"content-disposition" => array:1 [▼
0 => "attachment; filename=testdownload.zip"
]
]
#cacheControl: array:1 [▼
"public" => true
]
}
#content: null
#version: "1.0"
#statusCode: 200
#statusText: "OK"
#charset: null
}
Solution 1:[1]
Always clear your cache... I think it stores the filename before the renaming.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | poashoas |
