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

Laravel 6 , Laravel

Nicesnippets

228

28-09-2019


Hii Dev,

In this article, I will show you get all files in folder.Get list all files in specified folder using allfiles() and files().

All files return in array.In laravel you can using this function getRelativePathname() get all files name in folder.

Solution 1 for Laravel

First you can create public folder in test name folder.In folder you can multiple files.

then you can get all files using this method.

public function index()

{

$path = public_path('test');

$files = File::allFiles($path);

dd($files);

}

Solution 2 for Laravel

First you can create public folder in test name folder.In folder you can multiple files.

then you can get all files using this method.

public function index()

{

$path = public_path('test');

$files = File::files($path);

dd($files);

}

You can return folder in all files in array.

Solution for PHP

First you can create public folder in demo name folder.In folder you can multiple files.

then you can get all files using this method.

public function index()

{

$path = public_path('demo');

$files = scandir($path);

dd($files);

}

You can return folder in all files in array.

It will help you...