递归概述文件PHP / Laravel

时间:2016-08-11 14:43:16

标签: php file laravel recursion iterator

我有递归迭代器概述,我得到了所有文件,但也得到了所有目录。我只想概述文件。 我有以下代码:

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

 ?> 

1 个答案:

答案 0 :(得分:3)

您可以使用文件(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