Hello all, i have a folder called with firm, which is inside it i have several subfolder, let say: government University NGO Church But the problem is, the content of firm folder is not static, i mean, it can be added with another subfolder by the time being. I need to get them to a dropdown menu automatically. maybe like this <select name="folder"> <option value="">government</option> <option value="">University</option> <option value="">NGO</option> <option value="">Church</option> </select> PHP: So the option in this selection has to be increase automatically as many as firm folder. The point is how can i get all of subfolder name automatically? should i use dirname function, but how? Best regards Junandya
try this, hope it helps; <?php $dirs = array(); $dir = "firm"; $d = dir($dir); while(false != ($entry = $d->read())){ if(is_dir(implode('/', array($dir, $entry)))){ if(($entry != '.') && ($entry != '..')){ $dirs[] = $entry; } } } echo '<select name="folder">'; foreach($dirs as $dir){ echo sprintf("<option value=\"%s\">%s</option>",$dir,$dir); } echo '</select>'; ?> PHP:
<?php chdir('/put/the/directory/here'); $subfolders = glob('*', GLOB_ONLYDIR); /* example usage */ foreach($subfolders as $folder) echo '<option value=" '. $folder .' ">' . ucwords(strtolower(str_replace('_', ' ', $folder))) . '</option>'; PHP: