I have a folder named threads, and within that folder there are other folders. I am having trouble reading those folders into an array, and then putting them in a select box. Here is my code.
<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>
you have error in source code.
you are missing closing }
<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>
精彩评论