该下拉列表显示文件夹中的所有文件,其中一个文件将被选中使用。有没有办法显示加载页面时选择哪个文件?目前它每次说“选择一个文件”。下拉选择条目选择HTML表单元素
<select name="image" type="text" class="box" id="image" value="<?=$image;?>">
<option value='empty'>Select a file</option>
<?php
$dirname = "images/";
$images = scandir($dirname);
// This is how you sort an array, see http://php.net/sort
natsort($images);
// There's no need to use a directory handler, just loop through your $images array.
foreach ($images as $file) {
if (substr($file, -4) == ".gif") {
print "<option value='$file'>$file</option>\n"; }
}
?>
</select>