I finally got my directory listing script to work. I have another problem. After selecting initial directory if that directory has sub-directories, how do can I make a drop down box that is populated with the sub-directory names?
<?php
function readsubdirs($pathname) {
$root = opendir(".");
echo '<select name="'.$pathname.'">'."\n";
$selected = $_POST['seldir'];
while($subs = readdir($root)) {
if(filetype($subs) == "dir") {
if($subs != "." && $subs != "..") {
if($subs == $selected) {
$sel = " selected";
} else {
$sel = "";
}
echo '<option '.$sel.' value="'.$subs.'">'.$subs.'</option>'."\n";
}
}
}
echo '</select>';
}
function getfilelist($root) {
$dir = opendir($root);
$i = 0;
while($file = readdir($dir)) {
if($file != "." && $file != ".." && filetype($file) != "dir") {
if($i%2) {
echo '<div class="filelist_blue"><a href="'.$root.'/'.$file.'">'.$file.'</a></div>'."\n";
} else {
echo '<div class="filelist_gray"><a href="'.$root.'/'.$file.'">'.$file.'</a></div>'."\n";
}
$i++;
}
}
}
?>
<html>
<head>
<style type="text/css">
body {
margin:0;
color:#000000;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}
div.top {
top:0;
left:0;
position:relative;
width:100%;
}
div.selectdir {
display:block;
background-color:#FFFFFF;
padding:5px;
}
div.content {
width:100%;
top:10px;
position:relative;
}
div.filelist_blue {
display:block;
background-color:#ffffff;
padding:2px;
padding-left:15px;
}
div.filelist_gray {
display:block;
background-color:#E0E0E0;
padding:2px;
padding-left:15px;
}
div.bottom {
display:block;
color:#999999;
font-size:10px;
padding-top:15px;
text-align:center;
}
</style>
</head>
<body>
</div>
<div class="selectdir">
<form name="seldir" action="#" method="post">
<?
readsubdirs("seldir");
?>
<input type="submit" value="Select Directory" />
</form>
</div>
<div class="content">
<?
if(isset($_POST['seldir'])) {
$root = $_POST['seldir'];
} else {
$root = ".";
}
getfilelist($root);
?>
</div>
</body>
</html>