I'm trying to create a drop down menu that points to a directory and populates a drop down menu with the names of certain files in that directory using PHP.
Here's what I'm working with:
<?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>
";
}
}
$select .= "</select>";
closedir( $dh );
echo "$select";
?>
This bit of code is giving me an errors, and I'm not even really attached to it if there's a better way of trying to accomplish what I'm trying to do.