【发布时间】:2012-07-22 01:43:45
【问题描述】:
我正在尝试创建一个下拉菜单,该菜单指向一个目录,并使用 PHP 使用该目录中某些文件的名称填充下拉菜单。
这是我正在使用的:
<?php
$path = "pages/"; //change this if the script is in a different dir that the files you want
$show = array( '.php', '.html' ); //Type of files to show
$select = "<select name=\"content\" id=\"content\">";
$dh = @opendir( $path );
while( false !== ( $file = readdir( $dh ) ) ){
$ext=substr($file,-4,4);
if(in_array( $ext, $show )){
$select .= "<option value='$path/$file'>$file</option>\n";
}
}
$select .= "</select>";
closedir( $dh );
echo "$select";
?>
这段代码给了我一个错误,如果有更好的方法来尝试完成我正在尝试做的事情,我什至不会真正依恋它。
【问题讨论】:
-
readdir(): 提供的参数不是在线 ... 中的有效目录资源 ...
标签: php html file drop-down-menu directory