note 98707 deleted from function.opendir by danbrown
| From: | danbrown@php.net | Date: | Thu, 01 Jul 2010 22:54:42 +0000 |
| Subject: | note 98707 deleted from function.opendir by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170643@lists.php.net to get a copy of this message | ||
Note Submitter: bob
----
<?php
class FMFileSystem
{
var $_FILTER = null;
var $_LIST = Array();
function FMFileSystem()
{
}
function setFilter($filter)
{
if($filter == null)
{
$this->_FILTER = null;
return 0;
}
$this->_FILTER = explode(";", $filter);
}
function _READDIR($path, $recursive = false, $useFilter = false)
{
$dir = opendir($path);
while ($element = readdir($dir))
{
if($element != "." && $element != "..")
{
if(is_file($path."/".$element))
{
if($useFilter)
{
$pathinfo = pathinfo($path."/".$element);
$extension = $pathinfo["extension"];
if(!empty($this->_FILTER))
{
if(in_array($extension, $this->_FILTER))
{
array_push($this->_LIST, $path."/".$element);
}
}
}
else
{
array_push($this->_LIST, $path."/".$element);
}
}
if(is_dir($path."/".$element))
{
array_push($this->_LIST, $path."/".$element);
if(recursive)
{
$this->_READDIR($path."/".$element, $recursive, $useFilter);
}
}
}
}
closedir($dir);
}
function readDir($path, $recursive = false, $useFilter = false)
{
$this->_READDIR($path, $recursive, $useFilter);
return $this->_LIST;
}
}
?>
----------------------------
<?php
$FileSystem = new FMFileSystem();
$FileSystem->setFilter("jpg;png;gif;tif");
//parameters: path, recursive, useFilter
$Array = $FileSystem->readDir("images", true, true);
?>