Jur Hillebrink Jur Hillebrink - 3 months ago 13
PHP Question

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;
}
}

?>

Answer

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

Comments