Laravel - 链接到保存在存储文件夹中的文件 [英] Laravel - link to a file saved in storage folder
问题描述
当我们做这样的事情时:
Storage::disk('local')->put('file.txt', 'Contents');
如何在视图中创建指向该文件的链接?像这样:
下载文件
文档中有很多东西,但甚至没有一个示例如何创建指向该文件的链接
更新:
根据laravel docs,可以得到文件的URL像这样:
使用 IlluminateSupportFacadesStorage;$url = Storage::url('file1.jpg');
<块引用>
请记住,如果您使用的是本地驱动程序,所有文件应该是可公开访问的应该放在 storage/app/public
目录.此外,您应该在以下位置创建一个符号链接public/storage
指向 storage/app/public
目录.
希望这有帮助!
When we do something like this:
Storage::disk('local')->put('file.txt', 'Contents');
How do you make a link to that file in a view? Something like this:
<a href="path_to_file.txt">Download File</a>
there are so many things in documentation and yet not even one example how to create a link to that file
UPDATE:
According to laravel docs, You can get the URL to the file like this:
use IlluminateSupportFacadesStorage;
$url = Storage::url('file1.jpg');
Remember, if you are using the local driver, all files that should be publicly accessible should be placed in the
storage/app/public
directory. Furthermore, you should create a symbolic link atpublic/storage
which points to thestorage/app/public
directory.
Hope this helps!
这篇关于Laravel - 链接到保存在存储文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!