使用存储外观在Laravel 5.6中照亮\ Contracts \ Filesystem \ FileNotFoundException

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

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

使用存储外观在Laravel 5.6中照亮\ Contracts \ Filesystem \ FileNotFoundException

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

jacky598 回答:使用存储外观在Laravel 5.6中照亮\ Contracts \ Filesystem \ FileNotFoundException

直接从磁盘获取文件,而不是嵌套

$exists = Storage::disk('notas_xml')->exists('t.txt');
if ($exists) {
  $file = Storage::disk('notas_xml')->get('t.txt');
}

如果您没有在notas_xml中设置filesystems.php磁盘

$file = Storage::get('public/arquivos/notas_xml/t.txt');

要使用您的代码,您需要像config/filesystems.php

中那样设置磁盘
'notas_xml' => [
    'driver' => 'local','root' => storage_path('app/public/arquivos/notas_xml'),'url' => env('APP_URL') . '/storage','visibility' => 'public',],

像这样简单地获取文件

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

希望这会有所帮助

,

您需要获取以下代码的文件:

Storage::disk('notas_xml')->has('t.txt');

以上has方法可用于确定磁盘上是否存在给定文件:

请阅读文档https://laravel.com/docs/5.1/filesystem#retrieving-files

,

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

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

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

此立面Storage将在文件夹

中起作用
  

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"; }

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

无关。

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

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

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

  

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

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

  

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

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

  

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

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

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

本文链接:https://www.f2er.com/3159027.html

大家都在问