Mega Code Archive

 
Categories / Php / Code Snippets
 

List all files in a directory and place them in a select menu

<? //list all files in current directory andplace //ina select box function listfiles() { echo '<select name="filelist">'; $dir = opendir("./"); while($dirlist = readdir($dir)) { if ($dirlist[0] != "." && $dirlist[0] != ".." ) { echo "<option value=\"$dirlist\">$dirlist</option>"; } } echo '</select>'; closedir($dir); } echo '<form method="post" action="">'; listfiles(); echo '</form>'; ?>