我在存盤目錄中有一個 excel 檔案。我希望在單擊“下載 excel”按鈕后下載該檔案。我怎樣才能做到這一點?
uj5u.com熱心網友回復:
使用“storage_path()”,我們得到了存盤路徑。然后通過指定路徑和名稱我們可以下載檔案。我們需要將內容型別的標頭作為“應用程式/八位位元組流”傳遞
$file= storage_path(). "/excelFile.xlsx";
$headers = array(
'Content-Type: application/octet-stream',
);
return response()->download($file, 'excelFile.xlsx', $headers);
uj5u.com熱心網友回復:
您可以使用StorageLaravel的Facade。https://laravel.com/docs/8.x/filesystem#downloading-files
使用時,disk('local')它將查看storage/app目錄。
public function download()
{
return Storage::disk('local')->download('path-to-excel-file', 'filename.xlsx');
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/372883.html
