Michael Amici
Michael Amici

Reputation: 308

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> 

Upvotes: 0

Views: 356

Answers (1)

Vivek Goel
Vivek Goel

Reputation: 24160

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> 

Upvotes: 1

Related Questions