我是Laravel的初学者。
我有这样的代码:
$fileName = now()->toDateString() . '.docx';
$myFileName = 'Raport glowny'.docx;
try {
$objWriter->save(storage_path($fileName));
} catch (Exception $e) {
}
return response()->download(storage_path($fileName));我有两个文件名:
$ fileName = now () -> toDateString ()。'.Docx';$ myFileName =‘主报告’.docx;
$ fileName -服务器磁盘上文件的名称
$ myFileName -我希望将文件保存在用户磁盘上的文件名。
是否可以在download函数中指定文件名?
如果是,该怎么做呢?
发布于 2020-07-18 17:44:25
您可以将此名称作为第二个参数传递:
return response()->download(storage_path($fileName), $myFileName)发布于 2020-07-18 17:53:20
您可以使用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');https://stackoverflow.com/questions/62966987
复制相似问题