Jump to content


Photo

create a XML file of list of files in a directory


  • Please log in to reply
7 replies to this topic

#1 trendsetter

trendsetter
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 09 July 2006 - 10:51 AM

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.

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 09 July 2006 - 11:03 AM

what's the xml code like?
<image1.jpg/>?
Life's too short for arguing.

#3 trendsetter

trendsetter
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 09 July 2006 - 02:17 PM

its like:
<photos>
   <image photo="photo1">
      <title>This is photo 1</title>
   <image photo="photo2">
      <title>This is photo 2</title>
.
.
.
</photos>



#4 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 09 July 2006 - 02:46 PM

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.

<?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

Example $output:
<?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>


<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#5 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 09 July 2006 - 02:58 PM

I changed the XML a bit, didn't make sense to me.


Probably because it had an invalid syntax ;)

#6 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 09 July 2006 - 03:08 PM

Yeah, that's the one. ;)

<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#7 trendsetter

trendsetter
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 10 July 2006 - 05:25 AM

thank you very much ShogunWarrior, I will try the code.
sorry for the invalid syntax in xml.

#8 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 10 July 2006 - 05:49 AM

sorry for the invalid syntax in xml.


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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users