regarding a xml output

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vi54
Forum Newbie
Posts: 1
Joined: Sun Jan 31, 2010 7:38 pm

regarding a xml output

Post by vi54 »

Greetings reader,

I am new here and quite new to php. I foremost work inside of flash as 3, so slowly learning php along the way when needed.
But its interesting! and successfully managed myself to output a folder as xml in a php file.

I am aware that this is heavy on your server each time.
Instead I'd like to write this function out in a new xml file. for example "myoutputxml.xml"

Can someone please take a look at this code & help? I saw a few tuts on writing xml but somehow I can't bend my mind over this
and modify this myself.

There are tons of ways to list a directory but this code gives me alot of freedom for X amount of outputs vs different clients.
so I am found of this, and like to keep the function as it is but write an xml file. if that is possible?

Thank you in advance.

Code: Select all

<?php       
header("Content-type: application/xml");
ini_set('exif.encode_unicode', 'UTF-8');
echo "<?xml version='1.0' encoding='utf-8'?>\n";
 
 
function ListFolder($path)
{
 
    $dir_handle = @opendir($path) or die("Unable to open $path");
    $dirname = end(explode("/", $path));
    //display the target folder.
    if ($dirname == "IMAGES"){
      //do absolutely nothing :)
    } else {
      echo ("\t".'<slideshow path='.'"'.$dirname.'">');
    }
    while (false !== ($file = readdir($dir_handle)))
    {
        if($file!="." && $file!="..")
        {
            if (is_dir($path."/".$file))
            {
        //Display an eventual list of sub folders.
                ListFolder($path."/".$file);
        echo"</slideshow>\n";
            }
            else
            {
              echo '<image imageurl='.'"'.$file.'"'.'/>';
            }
        }
    }
    //closing the directory
    closedir($dir_handle);
    echo"</slideshow>\n";
}
ListFolder("IMAGES/TOPICNAME");
?>
 
Post Reply