Hay varias formas de resolverlo, te dejo una con iterators:
Código PHP:
Ver originalclass OnlyFileFilterIterator extends \FilterIterator
{
public function __construct($dirOrIterator = '.')
{
if (!is_dir($dirOrIterator)) { throw new \InvalidArgumentException('Expected a valid directory name');
}
$dirOrIterator = new \RecursiveDirectoryIterator($dirOrIterator);
}
if (!$dirOrIterator instanceof \DirectoryIterator) {
throw new \InvalidArgumentException('Expected a DirectoryIterator');
}
if ($dirOrIterator instanceof \RecursiveIterator) {
$iterator = new \RecursiveIteratorIterator($dirOrIterator);
} else {
$iterator = $dirOrIterator;
}
parent::__construct($iterator);
}
public function accept()
{
return $this->getInnerIterator()->current()->isFile(); }
}
uso:
Código PHP:
Ver original$filtered = new OnlyFileFilterIterator('/path/to/dir');