JoeAtRevolutionUnltd
Programmer
Is it possible to alphabetize files from a folder in a select box? I was told it is possible with just HTML but after a few hours of searching i'm coming up empty.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<?php
//deinf the array
$filelist = array();
//check to see if the folder exists
if ($handle = opendir('/usr/bin')) {
$i=0;
//loop through the folder and store in the array
while (false !== ($file = readdir($handle))) {
$filelist[$i] = $file;
$i++;
}
closedir($handle);
}
//sort the array alphabetically
asort($filelist);
//create the select box
echo "<select multiple=yes size=10>";
//loop through the array and add the options
foreach ($filelist as $k=>$v){
echo "<option value='$k'>$v</option>";
}
echo "</select>";
?>
while (false !== ($file = readdir($handle))) {
if (is_file($file)){
$filelist[] = $file;
}
}