此laravel代码下载文件,但其内容为空
$doc = Document::find($id);
$filePath = Storage::path($doc->path);
$header = ['Content-Type: application/pdf'];
return response()->download($filePath, $doc->name, $header);
您可以使用存储下载。确保$doc->path
返回存储文件夹的完整路径,或者如果只返回文件名,则必须将其附加在文件名之前
$doc = Document::find($id);
return Storage::download($doc->path);
参考编号:https://laravel.com/docs/8.x/filesystem#downloading-文件