PHP script that writes XML file based on directory contents

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
User avatar
scot
Forum Newbie
Posts: 3
Joined: Wed Apr 14, 2010 6:18 pm

PHP script that writes XML file based on directory contents

Post by scot »

Does anyone have a PHP script that I can use that will read the contents of a directory and create an xml file into that directory?
I am implementing Cooliris onto a Joomla site and I need to create a php file that I can use that will create an xml file of the images for Cooliris to read and display into its gallery viewer.
The plan is to have multiple galleries divided by different directories and I would use the php file followed by the variable indicating which directory I would need to create the xml file for.
I hope this makes sense.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP script that writes XML file based on directory conte

Post by requinix »

Creating an XML file is as simple as writing to any file.

Do you know the structure the XML needs to follow?
User avatar
scot
Forum Newbie
Posts: 3
Joined: Wed Apr 14, 2010 6:18 pm

Re: PHP script that writes XML file based on directory conte

Post by scot »

The XML will look like this: (Any ideas?)

Code: Select all

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
      <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"
      xmlns:atom="http://www.w3.org/2005/Atom">
      <channel>
          <item>
               <title>Picture A</title>
               <media:description> This one's my favorite.</media:description>
               <link>pl_images/A.jpg</link>
               <media:thumbnail url="http://example.com/pl_thumbs/A.jpg"/>
               <media:content url="http://example.com/pl_images/A.jpg"/>
          </item>          
      </channel>
      </rss>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP script that writes XML file based on directory conte

Post by requinix »

Oh. Just RSS.

Are you sure you need a PHP script to create a file? Can you just use the script as the RSS feed itself?
User avatar
scot
Forum Newbie
Posts: 3
Joined: Wed Apr 14, 2010 6:18 pm

Re: PHP script that writes XML file based on directory conte

Post by scot »

The ideas of using the php script as one php file is that new files will be added to the different directories and I want to use a script that creates a new xml file that represents the updated directory. Otherwise, you are right, and I would only need to just go ahead and create the xml file and embed that in the page. But, as I mentioned, the directories will grow over time and this php file will create a new xml file and write it to that directory every time and the gallery will be able to read this newly created xml file. I hope this makes sense.
Post Reply