What are some best practices for populating a select box in PHP based on directory contents?

When populating a select box in PHP based on directory contents, one approach is to use the `scandir()` function to retrieve the list of files in the directory, filter out any unwanted files (such as `.` and `..`), and then loop through the remaining files to populate the select box options.

<select name="files">
    <?php
    $directory = "path/to/directory";
    $files = array_diff(scandir($directory), array('..', '.'));
    
    foreach ($files as $file) {
        echo "<option value='$file'>$file</option>";
    }
    ?>
</select>