swamp Posted August 19, 2008 Share Posted August 19, 2008 Elo, I've done a bit of searching around for this but haven't got anywhere... I've got a directory called user-biogs each is titled with the username (eg) john white.txt is John White's user 'biog'. I want to be able to populate a drop down list with all the files in the user-biogs directory for a form. Also preferabley there would be no .txt extension. Any help/advice much appreciated! Cheers Link to comment https://forums.phpfreaks.com/topic/120333-solved-populate-a-drop-down-list-with-directory-contents/ Share on other sites More sharing options...
trq Posted August 19, 2008 Share Posted August 19, 2008 Have your filenames seriously got spaces in them? This could make your life a little more difficult. Link to comment https://forums.phpfreaks.com/topic/120333-solved-populate-a-drop-down-list-with-directory-contents/#findComment-619963 Share on other sites More sharing options...
Fadion Posted August 19, 2008 Share Posted August 19, 2008 Try a similiar approach: <form method="post" name="myform" id="myform" action=""> <select name="names" id="names"> <?php foreach(glob('*.txt') as $file){ //loop through all .txt files $file = substr($file, 0, strrpos($file, '.')); //strip the .txt extension echo "<option value='{$file}'>{$file}</option>"; //print the option } ?> </select> </form> @thorpe, except accessing files in http, which should show name%20surname, I don't see problems with spaces. Link to comment https://forums.phpfreaks.com/topic/120333-solved-populate-a-drop-down-list-with-directory-contents/#findComment-619965 Share on other sites More sharing options...
trq Posted August 19, 2008 Share Posted August 19, 2008 I don't see problems with spaces They dont play well with operating systems other than windows. Link to comment https://forums.phpfreaks.com/topic/120333-solved-populate-a-drop-down-list-with-directory-contents/#findComment-619972 Share on other sites More sharing options...
swamp Posted August 19, 2008 Author Share Posted August 19, 2008 Cheers Guilty - worked perfectly. Nice one Link to comment https://forums.phpfreaks.com/topic/120333-solved-populate-a-drop-down-list-with-directory-contents/#findComment-620015 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.