且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

不允许使用Laravel加载本地资源

更新时间:2022-11-16 23:26:13

不允许您的浏览器直接从硬盘驱动器加载该文件.在您看来,您可能会得到这样的信息:

Your browser is not allowed to directly load that file from your harddrive. In your view you are probably getting something like this:

<img src="C:\xampp\htdocs\socialNet\public\uploads\joew.png" />

您需要一个URL,浏览器才能访问该图像.在您看来,您需要以下内容:

You need a URL for the browser to access this image. In your view you need something like:

<img src="{{ asset('uploads/joew.png') }}" />

Laravel的asset()函数从public文件夹创建URL,并附加您提供的参数.因此,这将创建一个类似以下的URL: http://localhost/public/uploads/joew.png

The asset() function from Laravel creates a URL from the public folder and appends the param you give it. So this will create a URL like: http://localhost/public/uploads/joew.png

您指定的文件夹(storage_path)可能根本无法被浏览器读取.将上载更改为public_path('uploads'),它将可以访问.

The folder you specified (storage_path) is probably not readable for the browser at all. Change the uploads to public_path('uploads') and it will be accessible.