2011-02-13 210 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>