Current location: Hot Scripts Forums » Programming Languages » PHP » selecting directory's for drop down


selecting directory's for drop down

Reply
  #1 (permalink)  
Old 12-15-03, 02:12 PM
Squid44th Squid44th is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Question selecting directory's for drop down

I would like to be able to scan a directory and put the directories found into a drop down list to pic from, is that possible to do using php? I am thinking it can be done using an array. I am not that familiar with arrays, but am willing to learn. Need help Please
Reply With Quote
  #2 (permalink)  
Old 12-15-03, 02:33 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi there,

Quote:
I would like to be able to scan a directory and put the directories found into a drop down list to pic from, is that possible to do using php?
Yes, you can certainly do this with PHP.

Quote:
I am thinking it can be done using an array. I am not that familiar with arrays, but am willing to learn.
You need to use Directory Handle, which is more like a cursor through your directory. You can, of course, put the dir names into an array for better control.

Since you are willing to learn, here's a great resource for this:

PHP.net Directory Functions
http://php.net/dir

My tip would be to use readdir() in conjunction with is_dir(). Good luck!
__________________
Blavv =|
Reply With Quote
  #3 (permalink)  
Old 12-17-03, 09:16 AM
Trevor's Avatar
Trevor Trevor is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: Denver, Colorado
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
Code:
<select name="variable_name">
<?php
$directory = "your/directory";
$handle = opendir($directory);
while ($file = readdir($handle)) {
    $filelist[] = $file;
} while (list ($key, $file) = each ($filelist)) {
    if ($file == "." || $file == "..") {
        $a = 1;
    } else {
        echo("<option value=\"$file\" SELECTED>$file</option>\n");
    } 
} 
handle = closedir($directory);
?>
</select>
Here you go. This code works. But, if you are interested in learning, walk through each of the lines, looking up the functions. It's pretty straight forward.

Good Luck!
Trevor
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
mySQL: selecting values that do not exist bitesize PHP 9 02-20-04 11:47 AM
Selecting most popular perleo PHP 1 12-08-03 01:29 AM


All times are GMT -5. The time now is 07:33 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.