Hi all,
I’m creating a website and CMS with PHP and MySQL.
Now i’m busy with creating a image upload form.
I have a SimpleXML script to auto update my xml-file everytime I upload new images.
It all works but in order to work for my image gallery on the website I
need 1 more <…></…> (dunno what they are called).
But there is the problem! I just cant find out how to do that in my script!
Here is my script:
[php]<?php
$path_to_image_dir = ‘images’;
$xml_string = <<<XML
XML;
$xml_generator = new SimpleXMLElement($xml_string);
if ($handle = opendir($path_to_image_dir)){
while (false !== ($file = readdir($handle))){
if (is_file($path_to_image_dir.’/’.$file)){
$image = $xml_generator->addChild(‘photo’);
$image->addAttribute(“imageurl”, “$path_to_image_dir/$file”);
}
}
closedir($handle);
}
$file = fopen(‘gallery.xml’,‘w’);
fwrite($file, $xml_generator->asXML());
fclose($file);
?>[/php]
And here is my output in the XML file:
<?xml version="1.0"?>
<gallery>
<photo imageurl="images/105.jpg"/>
<photo imageurl="images/117.jpg"/>
<photo imageurl="images/123.jpg"/>
<photo imageurl="images/130.jpg"/>
</gallery>
Now as I said before I just need 1 more thing in the output.
I want my ouput to be like this:
<?xml version="1.0"?>
<gallery>
<photos>
<photo imageurl="images/105.jpg"/>
<photo imageurl="images/117.jpg"/>
<photo imageurl="images/123.jpg"/>
<photo imageurl="images/130.jpg"/>
</photos>
</gallery>
I want to be added but i just cant get it to work im my script!
If tried this before: (because it kinda makes sense to me)
[php]<?php
$path_to_image_dir = ‘images’;
$xml_string = <<<XML
XML;
$xml_generator = new SimpleXMLElement($xml_string);
[/php]
but that wont work because the output is then:
<?xml version="1.0"?>
<gallery>
<photos></photos>
<photo imageurl="images/105.jpg"/>
<photo imageurl="images/117.jpg"/>
<photo imageurl="images/123.jpg"/>
<photo imageurl="images/130.jpg"/>
</gallery>
I bet there is anyone around here that knows how to do it so please help me!
Sorry for my crappy english and i hope you understand what i mean.
Thanks in advance!
~RisingSun