Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursive overview files PHP/Laravel

I have the recursive iterator overview, I get all the files but also all the directory's. I want only a overview of the files. I have this code below:

<?php

$root = '/xampp/htdocs/systeembeheer/Storage/download/';

$iter = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS),
    RecursiveIteratorIterator::SELF_FIRST,
    RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied"
);

$paths = array($root);
foreach ($iter as $path => $dir) {
    if ($dir->isDir()) {
        $paths[] = $path;
    }
}

 ?> 
like image 819
jurh Avatar asked Oct 21 '25 03:10

jurh


1 Answers

You can use File (Illuminate\Support\Facades\File) facade:

    foreach (File::allFiles($root) as $file) {
        // $file->getFilename()
    }

API: https://laravel.com/api/5.2/Illuminate/Contracts/Filesystem/Filesystem.html

like image 131
Winogronko Avatar answered Oct 23 '25 20:10

Winogronko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!