Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get files list from public folder Laravel

I have images in my public folder (NOT STORAGE) :

enter image description here

And I want to get all these files in a list and for each one, I do something ... How can I do that?

like image 942
Saif Manwill Avatar asked Jan 13 '19 19:01

Saif Manwill


1 Answers

You could do this in one line:

use File;

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

// If you would like to retrieve a list of 
// all files within a given directory including all sub-directories    
$files = File::allFiles(public_path()); 

For more info, check the documentation.

Edit: The documentation is confusing. It seems, you would need to use the File Facade instead. I will investigate a bit more, but it seems to be working now.

Also, the result will be an array of SplFileInfo objects.

like image 177
Mozammil Avatar answered Oct 08 '22 08:10

Mozammil