[英]Laravel 7 Browser doesn't download file
我在 Windows 10 機器上運行 Xampp,我的目錄項目中有一個名為files.txt
的文件。
[...]存儲\\應用程序\\公共
我的config/filesystem.php
看起來像:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'permissions' => [
'file' => [
'public' => 0664,
'private' => 0600,
],
'dir' => [
'public' => 0775,
'private' => 0700,
],
],
],
在我的控制器上,我正在調用要下載的文件
return response()->download(storage_path("app\public\\files.txt"),'down.txt');
我收到 200 狀態 好的,我收到的標題內容:
Content-Disposition:附件; filename=files.txt ,在瀏覽器 Xhr devtools 上的響應中,我可以看到文件的內容,但不幸的是下載沒有發生。
您可以嘗試指定 header 嗎:
$content = storage_path("app\public\files.txt");
$fileName = 'down.txt';
$headers = [
'Content-type' => 'text/plain',
'Content-Disposition' => sprintf('attachment; filename="%s"', $fileName),
'Content-Length' => strlen($content)
];
return response()->download($content,$fileName, $headers);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.