MargateSteve Posted February 25, 2012 Share Posted February 25, 2012 I am using the code below to select a folder for an image upload. It works fine in that it does show all of the sub folders of the images folder but the first two options in the dropdown are . and .. I am not sure where they are coming from (although they do make me think of 'up one level' and 'go to top level option's) but cannot work out how to remove them. Also, I have been searching for a way to list the folders alphabetically but am stuck on that too! Thanks in advance for any suggestions Steve $dirs = scandir('/path/to/images'); foreach ($dirs as $dir) { if (is_dir('/path/to/'.$dir)) { echo '<option value="'.$dir.'">'.$dir.'</option>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/257789-directory-dropdown-problem/ Share on other sites More sharing options...
Pikachu2000 Posted February 25, 2012 Share Posted February 25, 2012 The current directory and directory one level back are exactly what they are. You can exclude them when you loop through the array in the foreach loop with && strpos($dir, '.') !== 0. Quote Link to comment https://forums.phpfreaks.com/topic/257789-directory-dropdown-problem/#findComment-1321279 Share on other sites More sharing options...
MargateSteve Posted February 26, 2012 Author Share Posted February 26, 2012 Perfect as always! As for the alphabetical order, once I added more folders I noticed that it is sorted alphabetically anyway! Thanks Steve Quote Link to comment https://forums.phpfreaks.com/topic/257789-directory-dropdown-problem/#findComment-1321284 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.