Originally posted by anothermacguy:
<STRONG>Raman? Did you get a chance to look at this?
Sorry to bug you...but I'm desparate.</STRONG>
Try this:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
<?
function listDir($theDir, $<font color = purple>self</font>, $topLevel) {
<font color = brown>// edit these to show images</font>
$folderIcon = <font color = red>""</font>;
$fileIcon = <font color = red>""</font>;
print(<font color = red>"<tr><td colspan=\"</font><font color = blue>2</font>\<font color = red>" align=\"</font>center\<font color = red>"><H2>Directory Listing <font color = green>for</font> "</font>);
<font color = green>if</font> ($theDir == <font color = red>"/"</font>) {
$theDir = $topLevel;
print(<font color = red>"/"</font>);
} <font color = green>else</font> {
$theDir = $topLevel . <font color = red>"/"</font> . $theDir;
$subPath = eregi_replace(<font color = red>"$topLevel/"</font>, <font color = red>""</font>, $theDir);
print(<font color = red>"/$subPath"</font>);
}
print(<font color = red>"</H2><hr></td></tr>\n"</font>);
<font color = green>if</font> ($theDir != $topLevel) {
$currPath = explode(<font color = red>"/"</font>,$subPath);
$lastItem = ((count($currPath))<font color = blue>-1</font>);
$upLevel = <font color = red>""</font>;
<font color = green>for</font> ($i=<font color = blue>0</font>; $i<$lastItem; $i++) {
<font color = green>if</font> ($i != <font color = blue>0</font>) {
$upLevel .= <font color = red>"/"</font>;
}
$upLevel .= $currPath[$i];
}
print(<font color = red>"<tr><td align=\"</font>left\<font color = red>"><A HREF=$<font color = purple>self</font>?currDir=$upLevel><-- Up one level</a><hr></td></tr>\n"</font>);
}
$level=<font color = blue>1</font>;
$dir = opendir($theDir);
<font color = green>while</font> (($theFile = readdir($dir)) != <font color = purple>FALSE</font>) {
$firstChar = substr($theFile,<font color = blue>0</font>,<font color = blue>1</font>);
<font color = green>if</font> ($firstChar != <font color = red>"."</font>) {
<font color = green>if</font> (is_dir($theDir.<font color = red>"/"</font>.$theFile)) {
<font color = green>if</font> ($subPath) {
$folderLine = <font color = red>"<tr><td><A HREF=$<font color = purple>self</font>?currDir=$subPath/$theFile>"</font>;
} <font color = green>else</font> {
$folderLine = <font color = red>"<tr><td><A HREF=$<font color = purple>self</font>?currDir=$theFile>"</font>;
}
<font color = green>if</font> ($folderIcon) {
$folderLine .= <font color = red>"<img src=images/foldericon.gif ALT=\"</font>dir: $theFile\<font color = red>">"</font>;
} <font color = green>else</font> {
<font color = brown>//$folderLine .= <font color = red>"dir: "</font>;</font>
$folderLine .= <font color = red>""</font>;
}
$folderLine .= $theFile;
$folderLine .= <font color = red>"</a></td></tr>\n"</font>;
print($folderLine);
} <font color = green>else</font> {
$theSize = round(filesize(<font color = red>"$theDir/$theFile"</font>)/<font color = blue>1000</font>,<font color = blue>2</font>);
$theDirClean = preg_replace(<font color = red>"/\s/"</font>,<font color = red>"%<font color = blue>20</font>"</font>,$subPath);
$theFileClean = preg_replace(<font color = red>"/\s/"</font>,<font color = red>"%<font color = blue>20</font>"</font>,$file);
<font color = green>if</font> ($theFileClean != '.htaccess') {
$theLink = <font color = red>"<p class=\"</font>defaultbody\<font color = red>">"</font>;
$theLink .= <font color = red>"<A HREF="</font> . $theDirClean . <font color = red>"/"</font> . $theFile . <font color = red>" TARGET=\"</font>stage\<font color = red>">"</font>;
$fileLine = <font color = red>"<tr><td>"</font> . $theLink;
<font color = green>if</font> ($fileIcon) {
$fileLine .= <font color = red>"<img src='images/fileicon.gif' ALT=\"</font>file: $theFile\<font color = red>">"</font>;
} <font color = green>else</font> {
<font color = brown>//$fileLine .= <font color = red>"file: "</font>;</font>
$fileLine .= <font color = red>""</font>;
}
$fileLine .= <font color = red>"$theFile </a></td><td align=\"</font>right\<font color = red>" valign=\"</font>top\<font color = red>">$theSizek</td></tr>\n"</font>;
print($fileLine);
}
}
}
}
}
?>
<html>
<head>
<title>Directory Listing</title>
</head>
<body bgcolor=<font color = red>"#FFFFFF"</font> text=<font color = red>"#<font color = blue>000000</font>"</font>>
<div align=<font color = red>"left"</font>>
<table border=<font color = red>"<font color = blue>0</font>"</font> cellpadding=<font color = red>"<font color = blue>5</font>"</font> cellspacing=<font color = red>"<font color = blue>0</font>"</font> width=<font color = red>"<font color = blue>95</font>%"</font>>
<?
$pathParts = pathInfo($HTTP_SERVER_VARS[<font color = red>"PATH_TRANSLATED"</font>]);
$<font color = purple>self</font> = $pathParts[<font color = red>"basename"</font>];
$topDir = $pathParts[<font color = red>"dirname"</font>];
<font color = green>if</font> (!($currDir)) {
$currDir = <font color = red>"/"</font>;
}
listDir($currDir,$<font color = purple>self</font>,$topDir);
?>
</table>
</div>
</body>
</html>
</font>[/code]
Note the lines that define "foldericon" and "fileicon". If you want icons, put the (relative or absolute) image paths here and they'll show up before each item. You can also edit lines 45 and 62 to provide a text descriptor for each item (eg: "dir:" and "file:"). I've already put in ALT tags, so this should work with text-based browsers as well.
If MacNN's boards mangle the above code, you can also
download it from http://www.isaka.net/misc/dir_list.php.sit.gz
Good luck, and sorry about the lack of documentation/commented code - it was a quick hack.
[ 07-11-2001: Message edited by: dogzilla ]