/* you call the function like this:
$img = array ('images');
ldir('images/', 0, 0, $img, 'images');
this will print the contents of directory images */
function ldir($path, $level, $m, $struct, $abs) {
$ignore = array ('cgi-bin', '.', '..', '.htaccess', '.t3hdirectives');
$dh = @opendir($path);
while (false !== ($file = readdir($dh))) {
if (!in_array($file, $ignore)) {
$spaces = str_repeat(' ', ($level*4));
$struct[$level] = $abs;
$url = '';
if ($level > 0) {
for ($i = 0; $i <= $level; $i += 1) {
$url .= $struct[$i];
$url .= '/';
}
$url .= $file;
}
else {
$url .= $abs;
$url .= '/';
$url .= $file;
}
if (is_dir("$path/$file")) {
echo "<a title="This is a directory. Nothing to link to.">$spaces $file</a> <i>(dir)</i><br/>";
$dir .= '/';
$dir .= $file;
ldir ("$path/$file", ($level + 1), $m, $struct, $file);
}
else {
switch ($m) {
case 0: echo "<a href="?cat=stuff&img=$url">$spaces $file</a><br/>"; break;
case 1: echo "<a href="$url">$spaces $file</a><br/>"; break;
case 2: echo "<a href="$url">$spaces $file</a><br/>"; break;
}
}
}
}
closedir($dh);
}
/* you can completely delete $m and the switch statement, i just used it because depending on the type the url differs */