Peuplarchie Posted June 28, 2009 Share Posted June 28, 2009 Good day to you all, I'm working on a piece of code which list directory into a dropdown box. No problem, with that : <p>List Box - Single Select<br> <select name="listbox" size="1"> <option selected>Click here to see them by themes</option> <?PHP if ($handle = opendir('themes/')) { while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..') { $fileName = str_replace('.mov', '', $file); echo '<option value="' . $file . '">' . $fileName . '</option>'; } } closedir($handle); } ?> </select> </p> Now what I would like to do is : 1- Read the directory recursively . Thanks ! Quote Link to comment https://forums.phpfreaks.com/topic/164006-listing-folders-in-list-box-folder-only-recursively/ Share on other sites More sharing options...
WolfRage Posted June 29, 2009 Share Posted June 29, 2009 I did this awhile back. You need to determine if you have a file or a directory when the listbox is created. PHP has built in functions for this and for determining if the file and or directory is readable. What I did is then attached a var called type to the post and indicated file or directory for each link. you can be creative with how you chose to go about this solution. So when they chose a directory then you will have the listbox regenerated with the next level. To achieve this effect you should make a session variable or again attach it to the selection as a tunneled location. I chose to use sessions so that I could hide the actual directory structure from the user. To make the form faster and more efficient I also used AJAX to re write the div each time until a file was selected. Also you will need special processing in order to handle a user selecting ".." in order to back up. This can cause a problem to because you need to detect that they do not back up further than you would like them to be able to; ie don't let them go deeper than the starting point. Quote Link to comment https://forums.phpfreaks.com/topic/164006-listing-folders-in-list-box-folder-only-recursively/#findComment-865944 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.