Drop Down Boxes from Directory Scan

I have a directory structure that is constantly being updated.

Config (Root)
–City (Sub-Dir)
----Address (Sub-Dir)
------File

I’m trying to create a script that will:

  1. Scan a directory (will be a root dir) and place the directory names in a drop down box.

  2. Choose option (dir) and a 2nd box will appear with subdirectores

  3. Once you select an option, a 3rd will be presented

  4. This directory will have 1 file that needs to be downloaded



<?php

$dir = "D9034-Configs";
if (isset($_GET['Site'])) { $Site = $_GET['Site']; } else { $Site = $_POST['Site']; }
if (isset($_GET['IP_Address'])) { $IP_Address = $_GET['IP_Address']; } else { $IP_Address = $_POST['IP_Address']; }

if (!(isset($Site)))
{
?>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<select name="Site" id="Site">
<?php
$output = shell_exec('ls ./'.$dir.'/');
$dirs = explode("\
", $output);
foreach ($dirs as $key => $value)
{
?> <option value="<?php echo $value?>"><?php echo $value?></option><?php
}
?>
</select>
</form>
<?php
}

if (isset($Site))
{
?>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<select name="Site" id="Site">
<?php
$output = shell_exec('ls ./'.$dir.'/');
$dirs = explode("\
", $output);
foreach ($dirs as $key => $value)
{
if ($value == $Site)
{
?> <option value="<?php echo $value?>" SELECTED><?php echo $value?></option><?php
}
else
{
?> <option value="<?php echo $value?>"><?php echo $value?></option><?php
}
}
?>
</select>
<select name="IP_Address" id="IP_Address">
<?php
$output = shell_exec('ls ./'.$dir.'/'.$Site.'/');
$dirs = explode("\
", $output);
foreach ($dirs as $key => $value)
{
?> <option value="<?php echo $value?>"><?php echo $value?></option><?php
}
?>
</select>
</form>
<?php
}

?>

Sorry, but I don’t see a question here.

You tried this and something did not work? Did you get any error messages?

ps you might also want to look at the PHP5 SPL DirectoryIterator in the manual or look for a [google]directoryiterator tutorial[/google]

Yeah, was that a question?

Apologies, but yes this is a question. I know the code is incomplete but the only thing I get is one (1) drop down box with the site. I can’t seem to get it to get past site where as if i choose a site, it will bring up a second drop down Dir with it’s subdirectory.