繁体   English   中英

[Laravel 5.2]即使存在存储文件也找不到

[英][ Laravel 5.2 ]Storage file not found even if it exists

\Storage::disk('verify_files')->put('verify-' . $fileCode[3], $fileCode[0]);

    $attach = \Storage::get(storage_path('app/public/verify') . '/' . 'verify-' . $fileCode[3]);

我正在使用上面的代码来生成和获取文件。

这是我使用的文件系统:

'verify_files' => [
        'driver' => 'local',
        'root' => storage_path('app/public/verify'),
        'visibility' => 'public',
    ],

当我使用file_exists()测试它时,它返回true,但是laravel FileNotFoundException in FilesystemAdapter.php line 61:返回FileNotFoundException in FilesystemAdapter.php line 61:

我在这里想念什么吗?

Storage Facade的get方法将自动查看默认磁盘的目录。 在这种情况下,您将使用storage_path传递文件的绝对路径,这是多余的,因为它将按原样在storage/app目录中查找。

而是执行Storage::disk('verify_files')->get('verify-' . $fileCode[3]) ;;

当您需要文件和目录的绝对路径时,请使用storage_path

除了您一直在使用其他方法之外,我遇到的错误与您相同:

            $parse = new Parsedown();
            $url = url('about.md'); // This would fail, because it returns absolute
            $url = 'about.md'; // the file is living in the root directory of public. This would succeed, because it's relative

            try { // catch file not found errors
                $about = File::get($url);
            } catch (Illuminate\Filesystem\FileNotFoundException $exception) {
                die ('Bad File');
            }

            echo $parse->text($about);

这来自此页面的组合,并且上述@SArnab提到的路径不必是绝对的。

除了我使用不同的方法外,我以前唯一的问题是我使用的是绝对路径,而不是现在使用的相对路径。

我只是以为我会在Laravel 5.2中添加这种替代方法来获取文件内容。

请享用!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM