如何从laravel 5.5的内部存储文件夹中获取文件?

Sar*_* TS 3 php laravel-5 laravel-5.5

我需要从 storage->app->public->huetten-> 它包含 17 个文件夹中列出文件。每个文件夹都包含图像。任何帮助,将不胜感激。

public function show($id)
    {
        if(!empty($id)) {
            $directories = Storage::disk('public')->allDirectories('huetten');
            foreach ($directories as $directory) {
                //dd($directory); // Here i get huetten/folder1

                $files = Storage::files($directory);
                foreach ($files as $file) {
                    dd($file); // But here files are not listing
                }


            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

Olu*_*ule 5

存储使用默认的 Filesystem 磁盘,config/filesystems.php其中在新的 Laravel 项目中设置为local storage/app/)。

我假设它在您的项目中设置为相同的值。

你想列出 storage/app/public 中的文件,这对应于config/filesystems.php.

在您的循环中,您可以通过获取公共磁盘的 Filesystem 实例来正确搜索目录,就像您在列出目录时所做的那样。

$files = Storage::disk('public')->files($directory);
/* [ 'storage/app/public/huetten/folder1/foo', 'storage/app/public/huetten/folder1/bar', ...] */
Run Code Online (Sandbox Code Playgroud)