2011-02-13 174 views
0

我有一个名为threads的文件夹,并且该文件夹中还有其他文件夹。我无法将这些文件夹读入数组,然后将它们放入选择框中。这是我的代码。从根目录中的文件夹获取目录PHP

<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> 
+1

,什么是确切的问题? – LeleDumbo

回答

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>