Rlemm1991
Rlemm1991

Reputation: 505

Laravel 5.3 store and read file directories

Currently trying to play about with files but struggling to figure out where to put them and how to read them back in a list.

Ive tried putting few test files into

$files = array();
$dir = opendir(asset('files'); // open the cwd..also do an err check.
while(false != ($file = readdir($dir))) {
    if(($file != ".") and ($file != "..") and ($file != "index.php")) {
            $files[] = $file; // put in array.
    }   
}

but it just returns blank despite having 3 test files in it.

Looked into larval recipes and suggestions say File:allFile() which isn't a supported method but its got me wondering apart from how to read files from a directory, where should i be really storing files I'm going to have on a server.

Upvotes: 3

Views: 2129

Answers (1)

aynber
aynber

Reputation: 23001

Laravel 5.3 uses Storage instead of Files. You can access all of the files in a directory using either of these two methods:

use Illuminate\Support\Facades\Storage;

$files = Storage::files($directory);

$files = Storage::allFiles($directory); // Includes subdirectories

Upvotes: 4

Related Questions