function generateFileSelect($title, $name = "file[]", $id = false) { $result = "<label><span>{$title}</span><select name=\"{$name}\"" . ($id ? " id=\"{$id}\"" : "") . ">"; foreach (collectFiles() as $file) { $file = addslashes($file); $result .= "<option value=\"{$file}\">{$file}</option>"; } $result .= "</select></label>"; return $result; }
function collectFiles ( $dir, $file_array ) { $directory_handle = opendir($dir); while ( false !== ($entry = readdir($directory_handle)) ) { if ( $entry != '.' and $entry != '..' and is_dir($dir.'/'.$entry) and is_numeric($entry) ) { $file_array = collectFiles($dir.'/'.$entry,$file_array); } elseif (is_file($dir.'/'.$entry)) { $dir_name = basename($dir); $regex = '[0-9]*'; if ( is_numeric($dir_name) and is_numeric($entry) ) { $file_array[] = $dir.'/'.$entry; } } } return $file_array; }