【发布时间】:2012-12-27 14:46:16
【问题描述】:
我想要一个下拉菜单来显示./files/$userid/ 中的所有子目录,而不仅仅是主文件夹。例如:/files/$userid/folder1/folder2/
我当前的代码是:
HTML:
<select name="myDirs">
<option value="" selected="selected">Select a folder</option>
PHP:
if (chdir("./files/" . $userid)) {
$dirs = glob('*', GLOB_ONLYDIR);
foreach($dirs as $val){
echo '<option value="'.$val.'">'.$val."</option>\n";
}
} else {
echo 'Changing directory failed.';
}
【问题讨论】:
-
你的问题是?请记住,制定需求不是编程问题。我建议您首先在网站上搜索您的要求,因为已经以各种方式询问和回答了列表目录。 So why not take a place at the bar and order your drink?
-
您需要使用 PHP 的原生 RecursiveDirectoryIterator 类。 This answer 应该有帮助。
-
我试过这个pastebin.com/fpJiiCbZ,但它不起作用。这是我得到的输出:i.imgur.com/gWt3U.png
-
您没有实现正确的代码。复制并粘贴上面答案中列出的 PHP 代码,它应该可以工作。
-
我做了,我不想获得文件名,只想要文件夹。答案中的“work.txt”是什么? (复制粘贴代码返回空下拉)
标签: php drop-down-menu recursion directory subdirectory