laravel下载响应文件名未更改
我正在使用laravel并尝试下载一个文件并更改文件名。 文档告诉我,我可以使用第二个参数作为新的文件名,但不知何故,文件名不会更改为“testdownload.zip”。我做错了什么 当我执行dd(response()->下载(存储路径('app/lorem-ipsum-shop-1.zip')、'testdownload.zip'、['Content-Type:application/zip'])时,返回以下内容(可能是perms/permissions 0100666吗?我在Windows上):laravel下载响应文件名未更改,laravel,downloadfile,Laravel,Downloadfile,我正在使用laravel并尝试下载一个文件并更改文件名。 文档告诉我,我可以使用第二个参数作为新的文件名,但不知何故,文件名不会更改为“testdownload.zip”。我做错了什么 当我执行dd(response()->下载(存储路径('app/lorem-ipsum-shop-1.zip')、'testdownload.zip'、['Content-Type:application/zip'])时,返回以下内容(可能是perms/permissions 0100666吗?我在Window
使用您提供的代码,我无法重现错误。我实际上得到了一个
testdownload.zip
文件。所以我认为你的应用程序的另一部分是干扰
- 您是否有任何可能调整响应(或响应标题)的中间件
- 你怎么称呼这个端点?直接从浏览器?通过AJAX
- 您能展示完整的控制器和
web.php
- 能否使用chrome调试工具验证响应头?它们看起来应该与下图类似。请注意
标题内容处置
始终清除缓存。。。我想它会在重命名之前存储文件名。为什么会被否决?dd(response()->下载(storage_path('app/lorem-ipsum-shop-1.zip')、'testdownload.zip'、['Content-Type:application/zip');;请检查。下载文件m i right>时是否要更改文件名?@VikasKatariya下载的文件名应与服务器上的原始文件名不同。我已使用dd()更新了问题,也许这可以解释更多问题。
// 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']);
}
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
}