Jump to content

create a XML file of list of files in a directory


trendsetter

Recommended Posts

Hi,
How to generate a XML of a list of files inside a directory. My directory contains picture files(.jpg). I am trying to make photo album in flash where i could use XML but I don't want to write the XML code for all the files in a folder.
I heard php could be helpful in generating XML. Please help me!
Thanks.
Well, this should do something like it:
I changed the XML a bit, didn't make sense to me.

It will run through a folder and create the XML for all the files in the folder,
you'll need to add something like fwrite to put it into a file or whatever you want to do.

[code]
<?php
$d = 'images/';
$endline = "\n";

$dir = opendir($d);

$output = '<?xml version="1.0" encoding="ISO-8859-1"?>'.$endline;
$output .= '<photos>'.$endline;
while($e = readdir($dir))
{
        if($e!='.' && $e!='..')
        {
                        $output .= '  <image photo="'.$e.'">'.$endline;
                        $output .= '       <title>'.$e.'</title>'.$endline;
                        $output .= '  </image>'.$endline;
        }
}
$output .= '<photos>'.$endline;

//code to write the $output to a file
[/code]

Example $output:
[code]
<?xml version="1.0" encoding="ISO-8859-1"?>
<photos>
  <image photo="Masses.jpg">
      <title>Masses.jpg</title>
  </image>
  <image photo="Mediteranean.jpg">
      <title>Mediteranean.jpg</title>
  </image>
  <image photo="Spider.jpg">
      <title>Spider.jpg</title>
  </image>
  <image photo="Taxi.jpg">
      <title>Taxi.jpg</title>
  </image>
  <image photo="Tie Hangar.jpg">
      <title>Tie Hangar.jpg</title>
  </image>
  <image photo="Trainyard.jpg">
      <title>Trainyard.jpg</title>
  </image>
<photos>

[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.