I'm trying to use this code to list the files alphabetically but for some reason there are listed both, the files from the folder "items"and "images". I want only the files from the folder "images" to be listed. <?php echo '<option value="null">Use url below</option>'; $dir = opendir('../items/images/'); while(false !== ($file = readdir($dir))) { if($file != "." && $file != ".." && $file != "Thumbs.db") { $fileList[] = trim($file); } } sort ($fileList); // sort the file list in the array reset ($fileList); // go back to the top of the array while (list ($key, $val) = each ($fileList)) { echo '<option value="'.$val.'">'.$val.'</option>'; } closedir($dir); ?> PHP: To list the files from the "items" folder i have this code : <?php echo '<option value="null">Use url below</option>'; $dir = opendir('../items'); while(false !== ($file = readdir($dir))) { if($file != "." && $file != ".." && $file != "Thumbs.db") { $fileList[] = trim($file); } } sort ($fileList); // sort the file list in the array reset ($fileList); // go back to the top of the array while (list ($key, $val) = each ($fileList)) { echo '<option value="'.$val.'">'.$val.'</option>'; } closedir($dir); ?> PHP: If i remove this last code the first will work correctly, any help how to make them both to work ?
you are adding the items to the same array try ... unset($fileList); ... before the second bit of code or use a different array ...