note 98707 added to function.opendir
| From: | bob at osu1 dot php dot net | Date: | Thu, 01 Jul 2010 22:53:32 +0000 |
| Subject: | note 98707 added to function.opendir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170642@lists.php.net to get a copy of this message | ||
<?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);
?>
----
Server IP: 217.160.235.204
Probable Submitter: 92.231.132.82
----
Manual Page -- http://www.php.net/manual/en/function.opendir.php
Edit -- https://master.php.net/note/edit/98707
Del: integrated -- https://master.php.net/note/delete/98707/integrated
Del: useless -- https://master.php.net/note/delete/98707/useless
Del: bad code -- https://master.php.net/note/delete/98707/bad+code
Del: spam -- https://master.php.net/note/delete/98707/spam
Del: non-english -- https://master.php.net/note/delete/98707/non-english
Del: in docs -- https://master.php.net/note/delete/98707/in+docs
Del: other reasons-- https://master.php.net/note/delete/98707
Reject -- https://master.php.net/note/reject/98707
Search -- https://master.php.net/manage/user-notes.php