我是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>.';更多推荐
发布评论