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

**URL:** <https://forum.kirupa.com/t/guys-i-need-help-tweaking-this-php-code-so-do-thru-directory-hierarchy/223004>\
**Category:** Uncategorized\
**Created:** [April 18, 2007, 5:35pm UTC](https://forum.kirupa.com/t/guys-i-need-help-tweaking-this-php-code-so-do-thru-directory-hierarchy/223004 "2007-04-18T17:35:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vthok](https://avatars.discourse-cdn.com/v4/letter/v/f05b48/32.png) [@vthok](https://forum.kirupa.com/u/vthok)\
**Post date:** [April 18, 2007, 5:35pm UTC](https://forum.kirupa.com/t/guys-i-need-help-tweaking-this-php-code-so-do-thru-directory-hierarchy/223004/1 "2007-04-18T17:35:37Z")

</div>

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;

?\>
