MysZon's avatar

How to get total files from a directory?

I have created a symbolic link through the command php artisan storage:link and I store all the files stored by my users there. Every user has a folder with name of the folder as md5($user_id). Then, I want to retrieve the files in my blade file. The problem is: my user can have multiple uploads so I need to get the number of files located in the directory. I searched the question and I found answers linking to this which has the solution that looks like this:

use Illuminate\Support\Facades\Storage;

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

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

, but the documentation is unclear. The $directory variable is not known and I don't know the root path of the method. So, what should my $directory variable contain so that I can include an image that is located in myProject/public/storage/user_uploads/$name_of_the_folder.

And by the way, I get the $name_of_the_folder dynamically and the storage folder in public is the symlink I have created with the above command.
0 likes
2 replies
tisuchi's avatar
tisuchi
Best Answer
Level 70

@myszon

Could you try adding in your config/filesystems.php file a user_images key:

'user_images' => [
    'driver' => 'local',
    'root'   => public_path() . '/storage/',
],

After that, try in your code to access via useR_images by doing below:

Storage::allFiles('user_images');

Check more: https://laravel.com/docs/5.0/filesystem#basic-usage

6 likes

Please or to participate in this conversation.