Marcos01 Posted August 25, 2008 Share Posted August 25, 2008 Hello all, I would like to display folders from the server in a dropdown box. This is the script I have so far: $folders = (ftp_nlist($conn,"../userfiles/images/projecten")); $recordcount = count($folders); echo '<br />'; echo '<select name="folders">'; for($i=1; $i<$recordcount, $i ++ { echo "<option>".$folders[$i]."</option>"; } echo '</select>'; Quote Link to comment https://forums.phpfreaks.com/topic/121231-solved-array-in-dropdown-box/ Share on other sites More sharing options...
DeanWhitehouse Posted August 25, 2008 Share Posted August 25, 2008 Is it not working?? Please use code tags Quote Link to comment https://forums.phpfreaks.com/topic/121231-solved-array-in-dropdown-box/#findComment-624941 Share on other sites More sharing options...
The Little Guy Posted August 25, 2008 Share Posted August 25, 2008 Try this (untested): echo '<select name="folders">'; foreach(glob("/path/to/directory/*",GLOB_ONLYDIR) as $dir){ echo "<option>".$dir."</option>"; } echo '</select>'; Quote Link to comment https://forums.phpfreaks.com/topic/121231-solved-array-in-dropdown-box/#findComment-624956 Share on other sites More sharing options...
Marcos01 Posted August 25, 2008 Author Share Posted August 25, 2008 Thanks for your replies. Yes, I am using code tags. Little guy, I inserted your code. The dropdown box appeared. However without content(folders). Quote Link to comment https://forums.phpfreaks.com/topic/121231-solved-array-in-dropdown-box/#findComment-625003 Share on other sites More sharing options...
The Little Guy Posted August 25, 2008 Share Posted August 25, 2008 did you set the path to the directory you would like to search, and leave the * ? It works for me... I used this: echo '<select name="folders">'; foreach(glob("../*",GLOB_ONLYDIR) as $dir){ echo "<option>".$dir."</option>"; } echo '</select>'; Quote Link to comment https://forums.phpfreaks.com/topic/121231-solved-array-in-dropdown-box/#findComment-625023 Share on other sites More sharing options...
Marcos01 Posted August 25, 2008 Author Share Posted August 25, 2008 I made a little error with the path. Yes, I left the * in place. Now I am getting content in it. It displays the whole path. I only need the folder. Any Idea on how to fix that? Thanks for your help!! Quote Link to comment https://forums.phpfreaks.com/topic/121231-solved-array-in-dropdown-box/#findComment-625028 Share on other sites More sharing options...
The Little Guy Posted August 25, 2008 Share Posted August 25, 2008 here I made a function, it returns an array of all the directories: http://phpsnips.com/snippet.php?id=60 Quote Link to comment https://forums.phpfreaks.com/topic/121231-solved-array-in-dropdown-box/#findComment-625035 Share on other sites More sharing options...
Marcos01 Posted August 25, 2008 Author Share Posted August 25, 2008 Sorry but I don't understand how to implement that in the code. Note that in the dropdown box I get to see the whole path instead of just the folders. Quote Link to comment https://forums.phpfreaks.com/topic/121231-solved-array-in-dropdown-box/#findComment-625077 Share on other sites More sharing options...
The Little Guy Posted August 25, 2008 Share Posted August 25, 2008 function getDirs($directory){ $opt = array(); foreach(glob(str_replace("//","/","$directory/*"),GLOB_ONLYDIR) as $dir){ $opt[] = str_replace($directory,"",$dir); } return $opt; } $dirList = getDirs('../'); // Modify this line's folder location, don't use an asterisk. echo '<select name="folders">'; foreach($dirList as $dir){ echo "<option>".$dir."</option>"; } echo '</select>'; Quote Link to comment https://forums.phpfreaks.com/topic/121231-solved-array-in-dropdown-box/#findComment-625086 Share on other sites More sharing options...
Marcos01 Posted August 25, 2008 Author Share Posted August 25, 2008 Little Guy, you are great! I hope this will help other people too. Thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/121231-solved-array-in-dropdown-box/#findComment-625119 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.