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.
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.