Anmerkung zu functions.upl.php: uplRecursiveDirectoryList
Verfasst: Sa 26. Mär 2005, 22:36
Das ist der Code zu uplRecursiveDirectoryList in functionsupl.php:
Sie funktioniert, aber so richtig verstehe ich den Code nicht, gerne nehme ich Erläuterungen an:
Der Codeteil:
wechselt IMHO zum einen das aktuelle Verzeichnis, ohne es wieder zurückzustellen und listet außerdem in $files nur Verzeichnisse auf (Test über @chdir). Wenn ja, dürfte die Überprüfung auf . und .. im darauffolgenden Code eigentlich entfallen dürfen.
Könnte die Funktion nicht so aussehen:
Gruß
HerrB
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