populate a xml element list - I think
Posted: Mon Nov 01, 2004 11:21 am
I received some great help over in the PHP code section for a script that populates files via a list and I'm now trying to merge this script to create a xml file for a photo gallery. I think I'm real close, because there are no errors, but it doesn't list the files in one of the elements. Hopefully someone can see an obvious mistake? This is what I have so far -
Nothing happens at all between the <file></file> element. Am I close here or do I need to start from scratch
This is my xml output -
Thanks for any help!!
Code: Select all
<?
$xml = '<?xml version="1.0" encoding="UTF-8" ?>';
$xml .= '<slideshow><settings><image_folder>/</image_folder>
<time>3</time><fade>1</fade><repeat>true</repeat>
<captions>true</captions></settings><images>';
$count = "1";
create_tree(".", '/^thumb_/');
function create_tree($file_dir, $filter = '') {
if ($handle = @opendir($file_dir))
{
$list = array();
while (false !== ($file = @readdir($handle))) {
if ($file != "." && $file != "..") {
if( !empty($filter) && !is_dir($file_dir . '/' . $file) )
if( !preg_match($filter, $file) )
continue;
$list[] = $file;
}
}
foreach($list as $file) {
if( is_dir($file_dir . '/' . $file) ) {
create_tree($file_dir . "/" . $file, $filter);
}
else
$xml .= '<image>';
$xml .= '<file>"" . $file_dir . "/" . $file . "\n"</file>';
$xml .= '<caption></caption>';
$xml .= '</image>';
$count++;
}
closedir($handle);
}
}
$xml .= '</images></slideshow>';
echo $xml;
?>This is my xml output -
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
- <slideshow>
- <settings>
<image_folder>/</image_folder>
<time>3</time>
<fade>1</fade>
<repeat>true</repeat>
<captions>true</captions>
</settings>
<images />
</slideshow>