我的資料存盤在資料庫中,我需要在文本檔案中將其取出。在磁盤上創建檔案沒有意義,但是嘗試用檔案生成回應是行不通的。找到了這樣的方法,但不起作用ERR_INVALID_RESPONSE
$contents = 'My data from db';
$filename = 'example.txt';
return response()->streamDownload(function () use ($contents) {
echo $contents;
}, $filename);
uj5u.com熱心網友回復:
在您的路線名稱中,路線名稱合理,例如:
Route::get('filename.txt', [FooController::class, 'foo']);
在 foo() 動作的控制器中:
$headers = [
'Content-Type' => 'application/plain',
'Content-Description' => 'File name',
];
$contents = 'My data from db';
return \Response::make($contents, 200, $headers);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/394016.html
標籤:拉拉维尔
