Jump to content

Archived

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

trendsetter

create a XML file of list of files in a directory

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.

Share this post


Link to post
Share on other sites
what's the xml code like?
<image1.jpg/>?

Share this post


Link to post
Share on other sites
its like:
[code]
<photos>
  <image photo="photo1">
      <title>This is photo 1</title>
  <image photo="photo2">
      <title>This is photo 2</title>
.
.
.
</photos>
[/code]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
[quote author=ShogunWarrior link=topic=99947.msg393997#msg393997 date=1152456375]I changed the XML a bit, didn't make sense to me.[/quote]

Probably because it had an invalid syntax ;)

Share this post


Link to post
Share on other sites
[quote author=trendsetter link=topic=99947.msg394266#msg394266 date=1152509106]
sorry for the invalid syntax in xml.
[/quote]

Doesn't matter - you are here to learn :D

Share this post


Link to post
Share on other sites

×

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.