Skip to content

Instantly share code, notes, and snippets.

@maartenJacobs
Created June 3, 2011 08:12
Show Gist options
  • Save maartenJacobs/1006042 to your computer and use it in GitHub Desktop.
Save maartenJacobs/1006042 to your computer and use it in GitHub Desktop.
Simple File filtering in PHP
class IncExtFilterIterator extends FilterIterator
{
protected $_extensions;
public function __construct($path, $includeExt)
{
parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
$this->_extensions = $includeExt;
}
public function accept()
{
$item = $this->getInnerIterator();
$filename = $item->getFileName();
if ($item->isFile() && in_array(pathinfo($filename, PATHINFO_EXTENSION), $this->_extensions)) {
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment