使用存储外观在Laravel 5.6中照亮\ Contracts \ Filesystem \ FileNotFoundException [英] Illuminate\Contracts\Filesystem\FileNotFoundException in Laravel 5.6 using Storage facade

查看:152
本文介绍了使用存储外观在Laravel 5.6中照亮\ Contracts \ Filesystem \ FileNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码返回一个奇怪的错误:

This code is returning an strange error:

$file = Storage::get(Storage::disk('notas_xml')->path('') . 't.txt');

如您所见,该文件确实存在.

As you can see the file does exist.

推荐答案

为了更好地理解所有这些……窍门在:config/filesystems.php

如果您有此代码(这是Github中Laravel的默认值)

To better understand all this... The trick is in: config/filesystems.php

If you have this code (which is the default value of Laravel in Github)

    'disks' => [
        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

此立面Storage将在文件夹

This Facade Storage will act in the folders

root_laravel_project/storage/app

root_laravel_project/storage/app

因此,如果您要检查是否存在"israel.txt"文件,则为
if( Storage::exists('israel.txt') ){ echo "File found. And it exists on the path: root_laravel_project/storage/app/israel.txt"; }

So if you want to check if an "israel.txt" file exists
if( Storage::exists('israel.txt') ){ echo "File found. And it exists on the path: root_laravel_project/storage/app/israel.txt"; }

请记住,到目前为止,它与符号链接php artisan storage: link

Remember that up to this point it has nothing to do with the symbolic link php artisan storage: link

此符号链接仅用于使存储"文件夹中的名为公共"的文件夹成为通过HTTP进行公共访问的一部分.

This symbolic link is only to make a folder called "public" within the "storage" folder be part of the public access through HTTP

    'disks' => [
        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],
        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

然后在进行符号交接时.您可以通过http(任何用户都可以访问)访问文件.
此示例假定您使用的是虚拟主机(如果没有,则建议您这样做,以建议在本地更好地工作)

Then at the time of doing the sym. You can access the files by http (which are public for any user)
This example assumes that you are using a virtual host (and if not, you must do it as a recommendation for work better locally)

http://root_laravel_project.test/storage/israel-alvarez.txt

http:// root_laravel_project.test/storage/israel-alvarez.txt

或者更好地理解为在没有虚拟主机的老式学校中

Or so that it is better understood as in the old school without a virtual host

http://localhost/public/storage/israel-alvarez.txt

http:// localhost/public/storage/israel-alvarez.txt

然后这些网址将显示在您的文件夹中

Then these urls will look inside your folder

root_laravel_project/storage/app/public/israel-alvarez.txt

root_laravel_project/storage/app/public/israel-alvarez.txt

Laravel的文档有些简短,在此问题上可能会造成混淆.但是,您只需要记住,一件事是通过存储外观"(这是上传并验证是否有文件的正确方法)进行访问,而另一件事是通过http(通过url)进行访问,这是象征性的链接(这是您已经给予用户下载文件或查看其是否为PDF的处理方式.)

Laravel's documentation is somewhat brief and can be confusing regarding this issue. But you just have to remember that one thing is to access through the "storage Facade" (which is the correct way to upload and verify if there are files) and another thing is to access through the http (through url) which is the symbolic link (which is the treatment you already give to users to download files or see if it is a PDF for example).

我希望它会有所帮助.美好的一天

I hope it helps. Good day

这篇关于使用存储外观在Laravel 5.6中照亮\ Contracts \ Filesystem \ FileNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆