Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a dropdown... 1

Status
Not open for further replies.

VAMick

Programmer
Nov 18, 2005
64
US
Is it possible to populate a dropdown menu with the file names that are found in a specified folder on the webserver? For instance, in my /images folder, the dropdown would have all the image files listed.

What I'm trying to do is make a page for the user to select a file and then associate keywords with the file, for later searching on.

Possible?
 
Just use PHP to get a directory listing and use it in a select list.

You can search the PHP forum here, or take a look at the manual:


Let us know your results!

X
 
Thanks, just searched over in the php forum and it's def pointing me in the right direction. I'll let you know how it turns out.
 
I started with these two chunks of code...

Code:
<?php
// Note that !== did not exist until 4.0.0-RC2

if ($handle = opendir('/path/to/files')) {
   echo "Directory handle: $handle\n";
   echo "Files:\n";

   /* This is the correct way to loop over the directory. */
   while (false !== ($file = readdir($handle))) {
       echo "$file\n";
   }

   /* This is the WRONG way to loop over the directory. */
   while ($file = readdir($handle)) {
       echo "$file\n";
   }

   closedir($handle);
}
?>
Example 2. List all files in the current directory and strip out . and ..
Code:
<?php
if ($handle = opendir('.')) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != "..") {
           echo "$file\n";
       }
   }
   closedir($handle);
}
?>

Then I just edited a bit to echo the value in the select form field instead of just outputing to the screen. Works great. Thanks for pointing me in the right direction.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top