Jump to content


Photo

drop box


  • Please log in to reply
1 reply to this topic

#1 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 08 June 2006 - 11:37 PM

I need help with loading all directories in a specific folder but where it loads in a drop down menu

#2 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 08 June 2006 - 11:46 PM

OK, should be fairly easy:
$dir = '/home/username/directory'; // this is your first folder
if(!$handle = opendir($dir)) // Check the folder can be opened
{
echo "Error: Directory could not be opened.";
exit; // If not, terminate the script
}

echo "<form><select name=\"dir_list\">"; // Start the drop-down menu

while(false !== ($file = readdir($handle))) // Loop through each entry in the folder
{
$fp = $dir . '/' . $file;
if($file == '.' || $file == '..' || !is_dir($fp)) // Ignore current (.) and previous (..) directory entries and anything that isn't a directory
{
continue;
}

echo "<option>$file</option>"; // Stick the directory into the drop-down menu

}
closedir($handle); // Close the directory
echo "</select></form>"; // Finish off the menu

[table]



Don't worry, the printer fairies will sort it out.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users