我是 Laravel 的初學(xué)者。我有這個代碼:$fileName = now()->toDateString() . '.docx';$myFileName = 'Raport glowny'.docx; try { $objWriter->save(storage_path($fileName)); } catch (Exception $e) { } return response()->download(storage_path($fileName));我有 2 個文件名:$ fileName = now () -> toDateString (). '.Docx'; $ myFileName = '主報告'.docx;$ fileName - 服務(wù)器磁盤上的文件名$ myFileName - 我希望將文件保存在用戶磁盤上的文件名。是否可以在下載功能中指定文件名?如果可以的話,該怎么辦呢?
2 回答

白衣非少年
TA貢獻(xiàn)1155條經(jīng)驗 獲得超0個贊
您可以將此名稱作為第二個參數(shù)傳遞:
return?response()->download(storage_path($fileName),?$myFileName)

子衿沉夜
TA貢獻(xiàn)1828條經(jīng)驗 獲得超3個贊
您可以使用Response::download($path);
Route::get('files/{order_id}/{file_name}', function($order_id,$file_name)
{
$path = storage_path().'/'.'app'.'/assets/OrderFiles/'.$order_id.'/attach/'.$file_name;
if (file_exists($path)) {
return Response::download($path);
}
})->name('GetAttachFile');
- 2 回答
- 0 關(guān)注
- 150 瀏覽
添加回答
舉報
0/150
提交
取消