Page 1 of 1

how can i automate maintainence of xml files

Posted: Wed Jul 05, 2006 1:17 am
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

Posted: Wed Jul 05, 2006 3:13 am
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. :)

Posted: Wed Jul 05, 2006 3:58 am
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...

Posted: Wed Jul 05, 2006 4:33 am
by Weirdan
Alternatively, you could serve xml dynamically by your PHP script (and store data somewhere else).

Posted: Wed Jul 05, 2006 4:52 am
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";

?>

Automating XML maintenance

Posted: Wed Jul 05, 2006 5:49 pm
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