<?php	
header('Content-Type: application/xml; charset=utf-8');
	// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts 
	$filter = ".mp3";
	// path to the directory you want to scan
	$directory = '/yuttadhammo/siri/www/files/diraudio/Yuttadhammo';
	
	$countno = 0;
	
	// read through the directory and filter files to an array
	$handle = opendir($directory);
	while (FALSE !== ($entry = readdir($handle)))
	{
		if($entry != '.' && $entry != '..')
		{
			$path = $directory.'/'.$entry;

			if(is_dir($path)) 
			{
				$handle2 = opendir($path);
				while (FALSE !== ($entry2 = readdir($handle2)))
				{
					$ps = strpos(strtolower($entry2), $filter);
					if (!($ps === false)) {  
						$items[$entry2] = $entry.'/'.$entry2; 
					} 
				}
				closedir($handle2);
				$itemsno[$entry] = $countno; 
				$countno++;
			}
		}
	}
	closedir($handle);

    $count = 0;
    $count2 = 0;
    $onehid = 0;
    $form = '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
';
	krsort($items);
	//$items = array_slice($items, 0, 20);
	foreach($items as $track => $file) {


		$form .= '	<url>
		<loc>http://yuttadhammo.sirimangalo.org/mp3-'.$file.'</loc>
	</url>
'; 
	}

	
	$form .= '</urlset>';
	echo $form;

?>
