<?phpheader('Content-Type: text/xml');//list_by_ext: returns an array containing an alphabetic list of files in the specified directory ($path) with a file extension that matches $extensionfunction list_by_ext($extension, $path){ $list = array(); //initialise a variable $dir_handle = @opendir($path) or die("Unable to open $path"); //attempt to open path while($file = readdir($dir_handle)){ //loop through all the files in the path if($file == "." || $file == ".."){continue;} //ignore these $filename = explode(".",$file); //seperate filename from extenstion $cnt = count($filename); $cnt--; $ext = $filename[$cnt]; //as above if(strtolower($ext) == strtolower($extension)){ //if the extension of the file matches the extension we are looking for... array_push($list, $file); //...then stick it onto the end of the list array } } if($list[0]){ //...if matches were found... sort($list); //...sort the list... return $list; //...return the array } else {//otherwise... return false; }}echo '<?xml version="1.0" encoding="ISO-8859-1"?>';echo "<recipe>\n";define('NL', chr(10));if($recipes = list_by_ext("docx", "./recipes/lunch/")){ for($i = 0; $i < count($recipes); $i++){ echo NL.'<type/>'.NL.'<fileName>'.$recipes[$i].'</fileName>'; }}echo "</recipe>\n";if(isDir($type)){list_by_ext('docx', './recipes/'.$type.'/');}if(isset($_GET['type'])){ $type = $_GET['type'];}?>