我对公共存储和存储本身有疑问
将文件插入存储设备后。 然后在视图页面中,我想显示我存储到存储器中的文件。 但是我有问题我有错误。
无法加载资源:服务器的响应状态为404(未找到)
Image Exist in the public storage folder & I've run the php artisan storage link
这是我的代码,如何将文件插入存储。
$filename = $request->file->getClientOriginalName();
$request->file->storeAs('storage',$filename);
这是我的代码,如何在视图页面上显示图像
@foreach($home_slider as $get_data_slider)
@if($get_data_slider->slider_sorting == '1')
<a href="{{$get_data_slider->link}}" target="_blank"><img src="{{ asset('/public/storage/'.$get_data_slider->file.'') }}" class="d-block w-100"></a>
@endif
@endforeach
我发现我无法访问localhost:8000 / public / storage / 1.jpg
但是当我使用localhost:8000 / storage / 1.jpg时,文件正在显示。 Showing image when the url is without public
谢谢..
答案 0 :(得分:3)
我必须从无业游民的框中运行php artisan storage:link
才能使符号链接真正生效。
答案 1 :(得分:0)
答案 2 :(得分:0)
使用助手asset()
时,您将直接位于公用文件夹中。
因此您的src应该是
src="{{asset('storage/'.$get_data_slider->file.'')}}".
用户可从浏览器访问的所有内容都位于公用文件夹中,因此,您不再需要在网址中添加“公用”。这就是为什么找不到第一个URL(localhost:8000 / public / storage / 1.jpg),而第二个URL(localhost:8000 / storage / 1.jpg)显示图像的原因。 使用第一个文件夹时,就像在公用文件夹中还有另一个名为public的文件夹(其中包含存储文件夹)。
答案 3 :(得分:0)
asset()-生成应用程序资产的URL。
url()-生成指向命名路由的URL。
asset()方法用于包含CSS / JavaScript / images文件,在这种情况下,您可以使用它
// specifictemplate.h
template <typename>
struct specificClass;
template <std::size_t I>
struct specificClass<ClassX<I>>
{
//Do the same only one time
};
文件必须位于公共文件夹中。
您的情况:
<link href="{{ asset('css/min.css') }}" rel="stylesheet">
<script src="{{ asset('use.typekit.net/zjb5wvv.js') }}"></script>
<img alt="logo" src="{{ asset('images/logo.png') }}">
PS :无需在asset()内显式添加公用文件夹;
答案 4 :(得分:0)
如果您使用Vagrant,则php artisan storage:link
应该在Vagrant下运行。否则,文件夹映射将是错误的,这就是为什么您得到404的原因之一。
因此,首先运行vagrant ssh
,然后找到您的项目文件夹并运行php artisan storage:link
。