blueman378 Posted March 25, 2008 Share Posted March 25, 2008 hi guys well heres my code: <?php echo "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">"; echo "<select name=\"cat\">"; $dir = '/avatars'; while ($folders = scandir($dir)) { if ($folders != "." && $folders != "..") { echo "<option value=\"$folders\">{$folders}</option>"; } } echo "</select></form>"; ?> and heres the output: <form method="post" action="/webspirited/forum/avatar.php"><select name="cat"><br /> <b>Warning</b>: scandir(/avatars) [<a href='function.scandir'>function.scandir</a>]: failed to open dir: No such file or directory in <b>/home/webspiri/public_html/test/webspirited/forum/avatar.php</b> on line <b>6</b><br /> <br /> <b>Warning</b>: scandir() [<a href='function.scandir'>function.scandir</a>]: (errno 2): No such file or directory in <b>/home/webspiri/public_html/test/webspirited/forum/avatar.php</b> on line <b>6</b><br /> </select></form> Link to comment https://forums.phpfreaks.com/topic/97769-load-foder-names-into-dropdown-list/ Share on other sites More sharing options...
Cep Posted March 25, 2008 Share Posted March 25, 2008 If the script is in the same level try, $dir = "./avatars"; Link to comment https://forums.phpfreaks.com/topic/97769-load-foder-names-into-dropdown-list/#findComment-500240 Share on other sites More sharing options...
ansarka Posted March 25, 2008 Share Posted March 25, 2008 Your code will result in to a infinite loop , i had modifed the code this will list all the folders in a combobox $dir = '/home/'; this will be considered as path from root directory if you want to give relative path give like $dir = '../classes/'; echo "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">"; echo "<select name=\"cat\">"; $dir = '/home/'; $folders = scandir($dir); foreach ($folders as $Fname) { if ($Fname != "." && $Fname != ".." && is_dir($dir.$Fname)) { echo "<option value=\"$Fname\">{$Fname}</option>"; } } echo "</select></form>"; Link to comment https://forums.phpfreaks.com/topic/97769-load-foder-names-into-dropdown-list/#findComment-500241 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.