开发者

Getting Directories from a folder in the root directory PHP

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> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜