简体   繁体   English

在 Laravel 中,如何访问存储目录中的所有文件?

[英]In Laravel, how can I access all files inside of the storage directory?

I have a Laravel application with a storage/app/icons directory, inside of which is about 200 files/images:我有一个带有 storage/app/icons 目录的 Laravel 应用程序,其中包含大约 200 个文件/图像:

在此处输入图像描述

My method to get retrieve all files inside of this folder is:我检索此文件夹中所有文件的方法是:

    public function index()
    {
        $icons = public_path('icons');
        $allIconsInsideFolder = Storage::allFiles($icons);
        return view('instapage', compact('allIconsInsideFolder'));
    }

However, it doesn't work correctly.但是,它不能正常工作。 How can I change the controller function so that it retrieves all files inside of the storage/app/icons directory?如何更改 controller function 以便它检索 storage/app/icons 目录中的所有文件?

you should pass the right path to the Storage::allFiles() method, witch look like it is in storage path in app folder then icons folder您应该将正确的路径传递给 Storage::allFiles() 方法,看起来它在 app 文件夹的存储路径中,然后是图标文件夹

please try:请试试:

$icons = storage_path('app/icons');
$allIconsInsideFolder = Storage::allFiles($icons);

or:或者:

$icons = storage_path('app/icons');
$allIconsInsideFolder = File::files($icons);

or或者

  $icons = storage_path('app/icons');
    $allIconsInsideFolder = scandir($icons);

it should work它应该工作

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

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