I've been trying to figure out how to do the same myself...
Here is the code:
$stime = gettimeofday();
/ some preliminaries... /
$root = getcwd();
$pre = explode("/", $REQUEST_URI);
array_pop($pre);
$prefix = join("/", $pre);
/ Uncomment the line below to create a tree of all files and directories on your webserver if the script
is in a subdirectory /
/ $root = str_replace($prefix, "", $root); */
$root .= "/";
/ Display server name and directory /
echo "<table cellspacing=0 cellpadding=0 border=0>\n";
echo "<tr><td><img align=absmiddle src=images/server.gif> [url]http://[/url]$SERVER_NAME";
if($root == getcwd()."/") { echo "$prefix/"; }
else { echo "/"; }
echo "</td></tr><tr><td><img align=absmiddle src=images/vertical.gif></td></tr>\n";
/ Recursion, here we go.. /
function list_dir($chdir)
{
/ some globals, some cleaning /
global $root, $display, $prefix, $PHP_SELF;
unset($sdirs);
unset($sfiles);
chdir($chdir);
$self = basename($PHP_SELF);
/ open current directory /
$handle = opendir('.');
/ read directory. If the item is a directory, place it in $sdirs, if it's a file of the type
php, htm, html or shtml and not this file, put it in $sfiles */
while ($file = readdir($handle))
{
if(is_dir($file) && $file != "." && $file != "..")
{ $sdirs[] = $file; }
elseif(is_file($file) && $file != "$self" && ereg("(php|htm|html|shtml)$", $file))
{ $sfiles[] = $file; }
}
/* count the slashes to determine how deep we're in the directory tree and how many
* nice bars we need to add */
$dir = getcwd();
$dir1 = str_replace($root, "", $dir."/");
$count = substr_count($dir1, "/") + substr_count($dir1, "\\");
chdir($chdir);
/* iterate through the array of files and display them */
if(is_array($sfiles)) {
sort($sfiles);
reset($sfiles);
if(!isset($display))
{ $display = "both"; }
$sizeof = sizeof($sfiles);
/* what file types shall be displayed? */
for($y=0; $y<$sizeof; $y++) {
if(ereg("php$", $sfiles[$y]) && ($display == "both" || $display == "PHP")) {
echo "<tr><td>";
for($z=1; $z<=$count; $z++)
{ echo "<img align=absmiddle src=images/vertical.gif> "; }
if($y == ($sizeof -1))
{ echo "<img align=absmiddle src=images/verhor1.gif>"; }
else
{ echo "<img align=absmiddle src=images/verhor.gif>"; }
echo "<img align=absmiddle src=images/php.gif> ";
echo "<a href=\"$prefix$dir1/$sfiles[$y]\">$sfiles[$y]</a></td></tr>";
}
elseif(ereg("(html|htm|shtml)$", $sfiles[$y]) && ($display == "both" || $display == "HTML")){
echo "<tr><td>";
for($z=1; $z<=$count; $z++)
{ echo "<img align=absmiddle src=images/vertical.gif> "; }
if($y == ($sizeof -1))
{ echo "<img align=absmiddle src=images/verhor1.gif>"; }
else
{ echo "<img align=absmiddle src=images/verhor.gif>"; }
echo "<img align=absmiddle src=images/html.gif> ";
echo "<a href=\"$prefix$dir1/$sfiles[$y]\">$sfiles[$y]</a></td></tr>\n";
}
}
echo "<tr><td>";
for($z=1; $z<=$count; $z++)
{ echo "<img align=absmiddle src=images/vertical.gif> "; }
echo "</td></tr>\n";
}
}
list_dir($root);
echo "</table>\n";
Currently it displays the name of the file hyperlinked. Would like it to display the title name hyperlinked.
Any suggestions would be gratefully appreciated.