how can i automate maintainence of xml files

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
zubo
Forum Newbie
Posts: 2
Joined: Wed Jul 05, 2006 12:11 am

how can i automate maintainence of xml files

Post by zubo »

Hi all
I'm hoping someone can help me with some code snippets.
Oldtime programmer - just trying to revisit coding so know principles of what to do but not how to.

I am creating a pic gallery in flash (i am using a variation of someone else's) which uses an xml file containing the filename of pics to display.
I will refresh the gallery every day but I do not want to keep editing the xml file. So I thought I could write a little program in php which will read the contents of a specific directory and rewrite the xml file.
Anyone help me with the php code??

thanks

george
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

You'll be needing to use the function opendir() and readdir (link is on opendir link)

That should get you on your way.. have a go, any problems.. ask here. :)
rameshmrgn
Forum Newbie
Posts: 15
Joined: Sat Jun 17, 2006 1:01 am

Post by rameshmrgn »

you can use just read & write file operations.

Then you can run the same file automatically within a time period.

To run it automatically, u should use crontab availble in unix or linux...
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Alternatively, you could serve xml dynamically by your PHP script (and store data somewhere else).
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

an example of what I was referring to, but using glob instead of opendir/readddir

Code: Select all

<?php

$images = glob ('/path/to/images/*.{jpg,gif,png,etc}', GLOB_BRACE);

echo "<?xml version=\"1.0\"?>\n\t<files>\n";

foreach ($images as $img) {
    echo "\t\t<file>{$img}</file>\n";
}

echo "\t</files>\n";

?>
zubo
Forum Newbie
Posts: 2
Joined: Wed Jul 05, 2006 12:11 am

Automating XML maintenance

Post by zubo »

Guys

you are awesome! I really appreciate the pointers, now to research your suggestions and cut some code...
well not now - it's way past my bedtime, but tomorrow after work

thank you all

george
Post Reply