Hi there this is my first post, and YES i'm a complete newbie to php....
I'm using this code to create a XML Document
//add album
if ($_POST['btnAdd']=="Add"){
$xmlDoc = new DOMDocument();
$xmlDoc->load("../flash/galeria/gallery.xml");
$albums = $xmlDoc->getElementsByTagName("albums")->item(0);
$new_album = $xmlDoc->createElement("album");
$albums->appendChild($new_album);
$xmlDoc->save("../flash/galeria/gallery.xml");
redirect();
}
//uploads the image, moves to the image directory, resample and create the thumbnail
if ($_POST["btnUpload"]=="Upload"){
session_start();
$target_dir = "../flash/galeria/images/big/"; //default directory for uploading images
$file_name = basename( $_FILES['uploadedfile']['name']);
$target_path = $target_dir . $file_name; //adding the file name
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
$msg= "The file ". $file_name." has been uploaded";
$xmlDoc = new DOMDocument();
$xmlDoc->load("../flash/galeria/gallery.xml");
$albums = $xmlDoc->getElementsByTagName("album");
$albums_count = $albums->length;
for ($i=0; $i < $albums_count; $i++){
$album = $albums->item($i)->getAttribute("title");
if ($album == $_POST['listAlbum']){
$new_img = $xmlDoc->createElement("image");
$new_img->setAttribute("title","");
$new_img->setAttribute("date","");
$new_img->setAttribute("thumbnail",$file_name);
$new_img->setAttribute("image",$file_name);
$new_img->setAttribute("link","");
$new_img->nodeValue = "";
$album_node = $albums->item($i)->appendChild($new_img);
}
}
$xmlDoc->save("../flash/galeria/gallery.xml");
} else{
$msg= "There was an error uploading the file, please try again!";}}
the problem is when adding nodes, it goes only on the same line, the result is this
<albums>
<album title="malas" description="Catálogo de malas"><image title="" date="" thumbnail="PIC_0310.JPG" image="PIC_0310.JPG" link=""></image></album></albums>
and i would like to be this, as it would be more readable
<albums>
<album title="malas" description="Catálogo de malas">
<image title="" date="" thumbnail="PIC_0310.JPG" image="PIC_0310.JPG" link=""></image>
</album>
</albums>
Can someone plz help this newbie?
Thanks