我有一个名为threads的文件夹,在该文件夹中还有其他文件夹。我无法将这些文件夹读入数组,然后将它们放入选择框中。这是我的代码。
<select value="Please Select a Genre" >
<?php
$threads = array();
if ($handle = opendir('/Threads/')) {
while (false != ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
array_push($threads,"$file");
print_r ($threads);
}
}
sort($threads);
print_r ($threads);
for ($i = 0; $i < count($threads); $i++) {
print "<option value=\"$threads[$i]\">$threads[$i]</option>";
}
closedir($handle);
?>
</select>
<br />
<input type=\"submit\" name=\"submit\" value=\"Submit\" />
</form>
</center>
</body>
</html>
答案 0 :(得分:1)
您在源代码中有错误。
你错过了关闭}
<select value="Please Select a Genre" >
<?php
$threads = array();
if ($handle = opendir('/Threads/')) {
while (false != ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
array_push($threads,"$file");
print_r ($threads);
}
}
}
sort($threads);
print_r ($threads);
for ($i = 0; $i < count($threads); $i++) {
print "<option value=\"$threads[$i]\">$threads[$i]</option>";
}
closedir($handle);
?>
</select>
<br />
<input type=\"submit\" name=\"submit\" value=\"Submit\" />
</form>
</center>
</body>
</html>