Code: Alles auswählen
function uplRecursiveDirectoryList ($directory, &$rootitem, $level)
{
$dirhandle = @opendir($directory);
if (!$dirhandle)
{
} else {
unset($files);
//list the files in the dir
while ($file = readdir ($dirhandle))
{
if ($file != "." && $file != "..")
{
if (@chdir($directory.$file."/"))
{
$files[] = $file;
}
}
}
if (is_array($files))
{
sort($files);
foreach ($files as $key => $file)
{
/* We aren't using is_dir anymore as that function is buggy */
$olddir = getcwd();
if ($file != "." && $file != "..")
{
if (@chdir($directory.$file."/"))
{
unset($item);
$item = new TreeItem($file, $directory.$file."/",true);
$item->custom["level"] = $level;
if ($key == count($files)-1)
{
$item->custom["lastitem"] = true;
} else {
$item->custom["lastitem"] = false;
}
$item->custom["parent"] = $directory;
$rootitem->addItem($item);
$old = $rootitem;
uplRecursiveDirectoryList($directory.$file."/", $item, $level + 1);
$rootitem = $old;
chdir($olddir);
}
}
}
}
}
@closedir ($dirhandle);
}
Der Codeteil:
Code: Alles auswählen
while ($file = readdir ($dirhandle))
{
if ($file != "." && $file != "..")
{
if (@chdir($directory.$file."/"))
{
$files[] = $file;
}
}
}
Könnte die Funktion nicht so aussehen:
Code: Alles auswählen
function uplRecursiveDirectoryList ($directory, &$rootitem, $level)
{
$dirhandle = @opendir($directory);
if (!$dirhandle)
{
} else {
unset($files);
//list the files in the dir
$olddir = getcwd();
while ($file = readdir ($dirhandle))
{
if ($file != "." && $file != "..")
{
if (@chdir($directory.$file."/"))
{
$files[] = $file;
}
}
}
@chdir($olddir);
if (is_array($files))
{
sort($files);
foreach ($files as $key => $file)
{
/* We aren't using is_dir anymore as that function is buggy */
$olddir = getcwd();
if (@chdir($directory.$file."/"))
{
unset($item);
$item = new TreeItem($file, $directory.$file."/",true);
$item->custom["level"] = $level;
if ($key == count($files)-1)
{
$item->custom["lastitem"] = true;
} else {
$item->custom["lastitem"] = false;
}
$item->custom["parent"] = $directory;
$rootitem->addItem($item);
$old = $rootitem;
uplRecursiveDirectoryList($directory.$file."/", $item, $level + 1);
$rootitem = $old;
}
@chdir($olddir);
}
}
}
@closedir ($dirhandle);
}
HerrB