Guys I need help tweaking this PHP code so do thru directory hierarchy

Original code just looks at current directory that gallery.swf is located in (doesn’t go thru directories). What
I want it to do is go search ./galleries/ directory and go thru each of the directories
underneath ./galleries. Then I want it to spit out XML like it
does already but add an attribute tag that tells me the directory
that picture file came from. Reason for all this is that I cna then
use gallery.swf to just give me particular jpegs from a specific
directory depending if I hit “directory 1 button”, “directory 2 button”, etc.

Thanks.

Orginal code shown here:

<?

$xml = ‘<?xml version=“1.0”?’.’>’;

$handle = opendir(".");

while ( ($file=readdir($handle)) !== false ) {

if ( !is_dir($file) ){

	$pic = @getimagesize($file);

	if($pic != false && $pic[2] == 2){

		$xml .= '&lt;img src="'.$file.'" width="'.$pic[0].'" height="'.$pic[1].'" /&gt;';

	}

}

}

echo $xml;

?>