我正在开发一个laravel应用程序,我想通过单击一个按钮下载文件。我将文件存储在其中/storage/app/public/1.pdf
并创建了指向该public
文件夹的符号链接。现在,我尝试了多种下载文件的方法,但是每次都会收到错误消息File Not Fount Exception at path
。
我尝试了以下下载文件的方法:
1 -
$name = "file.pdf";
$file = storage_path(). "/app/public/1.pdf";
$headers = array(
'Content-Type: application/pdf');
return Storage::download($file, $name, $headers);
2 -
$name = "file.pdf";
$file = public_path(). "/storage/1.pdf";
$headers = array(
'Content-Type: application/pdf',
);
return Storage::download($file, $name, $headers);
3 -
$name = "file.pdf";
$file = Storage::url("1.pdf");
$headers = array(
'Content-Type: application/pdf',
);
return Storage::download($file, $name, $headers);
这是我收到的错误消息:
我尝试了很多次,但对我没有任何帮助。任何帮助都需要提前感谢。
来自文档:
本地驱动程序
使用
local
驱动程序时,所有文件操作都相对于配置文件中root
定义的目录filesystems
。默认情况下,此值设置为storage/app
目录。
因此,如果文件存储在中storage/app/public/1.pdf
,请不要将这样的绝对路径传递到Storage Facade:
$file = storage_path(). "/app/public/1.pdf";
return Storage::download($file);
而是使用相对于配置文件中root
定义的目录的路径filesystems
:
$file = "public/1.pdf";
$name = "file.pdf";
return Storage::download($file, $name);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句