如何使用laravel显示存储在磁盘上的文件(How to display a file that is stored on disk using laravel)

编程入门 行业动态 更新时间:2024-10-26 12:26:24
如何使用laravel显示存储在磁盘上的文件(How to display a file that is stored on disk using laravel)

我是laravel的新手,在阅读Dayle Rees关于检索数据的书时,我遇到了这个简洁的文件代码并将文件存储在磁盘上。

Route::post('handle-form', function() { $name = Input::file('book')->getClientOriginalName(); Input::file('book')->move('/storage/directory', $name); return 'File was moved.'; });

我的问题是如何显示已存储给用户的文件。

I am new to laravel and while reading Dayle Rees's book on retrieving data I came across this succinct code for files and storing the file on disk.

Route::post('handle-form', function() { $name = Input::file('book')->getClientOriginalName(); Input::file('book')->move('/storage/directory', $name); return 'File was moved.'; });

My question is how do you display the file that has been stored to the user.

最满意答案

将文件视为您希望人们使用网址访问的常用文件。

因此,假设您的网站的公共路径位于/var/www/myproject/public ,您需要将输入文件移动到该文件夹​​中。 例如:

Input::file('book')->move('/var/www/myproject/public/uploads', $name);

然后,您可以使用典型的HTML <a>标记显示您的文件:

return 'File was moved. <a href="/uploads/'. $name .'">Access your file</a>.';

Treat the file as a usual file that you would like people to access with a url.

So suppose that your website's public path is at /var/www/myproject/public, you will want to move the input file into that folder. For example:

Input::file('book')->move('/var/www/myproject/public/uploads', $name);

Then you can display your file with a typical HTML <a> tag:

return 'File was moved. <a href="/uploads/'. $name .'">Access your file</a>.';

更多推荐

本文发布于:2023-04-29 09:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335869.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   磁盘   文件   laravel   disk

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!