How to Get all Files in a Directory in Laravel 8 -?

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Hello Dev’s, Now in this article, I will teach you how to get all files in folder in laravel application. To get list of all files in specified folder by using allfiles() and files() function. Here we know how to Get all Files in a Directory.

All files function is return in array.In laravel application we can using by this function getRelativePathname() get all files name in folder of application.

Solution 1 for Laravel

At First we can create a public folder in test name folder in our project. In this folder we can upload multiple files.

public function index()
   {
      $path = public_path('test');
      $files = File::allFiles($path);
    
      dd($files);
   }

So then we also can get all files list by using this method.

Solution 2 for Laravel

For our next solution at first we can create a public folder in test name folder in our project.In this folder we can upload multiple files.

then we can get all files list by using this method.

public function index()
   {
      $path = public_path('test');
      $files = File::files($path);
    
      dd($files);
   }

we can return folder in all files in a array.

Solution for PHP

For php solution at first we can create a public folder in demo name folder. In this folder we can store multiple files.

Then we can get all files by using this method.

public function index()
   {
      $path = public_path('demo');
      $files = scandir($path);
      dd($files);
   }

We can return folder in all files list in array.

Read Also : How Laravel Livewire Click Event work?

Thanks for read. I hope it help you. For more you can follow us on facebook

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →