joshjaybee
December 8th, 2008, 01:54 AM
Hello,
I'm trying to develop a backend for a gallery that uses Flash and XML. I've come to the stage of getting very angry with myself that I cannot get this to work, I've tried so many different ways and ideas and tutorials and snippets to try and get this to work, but nothing.
I did discover this http://www.kirupa.com/net/writingXML_pg4.htm (http://www.kirupa.com/net/writingXML_pg4.htm) and thought what a great resource exactly what I want, except it's for .NET. So I went about transferring it to PHP. But alas Epic Failure!
Just need some help on what’s wrong here I've posted both the XML document and the php code. Basically I'm trying to add images to an album. Once I get this working (with your help) I will start on the form to submit the pictures and also work on another php class to create a new album, instead of just having the 2 that are in the XML file. You will understand this when you see the XML file.
I'll keep this a working project on here for others who are in the same boat. I feel using Flash and XML for galleries is great however manually entering data is not my idea or a complete system.
Thanks
Josh
<?php
$xmldoc = loadXMLDoc('gallery.xml');
function AddImage($title, $date, $thumbnail, $image, $description)
{
//
// Initialize albumsElement if you are adding your first album.
//
$albumsElement = $xmlDoc.GetElementById("album");
//
// Adding and populating the elements
//
$imageElement = xmlDoc.CreateElement("image");
$descriptionElement.InnerText = $description;
$imageElement.AppendChild($descriptionElement);
$imageAttribute = xmlDoc.CreateAttribute("title");
$imageElement.SetAttributeNode($imageAttribute);
$imageAttribute.Value = $title;
$imageAttribute = xmlDoc.CreateAttribute("date");
$imageElement.SetAttributeNode($imageAttribute);
$imageAttribute.Value = $date;
$imageAttribute = xmlDoc.CreateAttribute("thumbnail");
$imageElement.SetAttributeNode($imageAttribute);
$imageAttribute.Value = $thumbnail;
$imageAttribute = xmlDoc.CreateAttribute("image");
$imageElement.SetAttributeNode($imageAttribute);
$imageAttribute.Value = $image;
$albumsElement.AppendChild($imageElement);
}
function WriteToDisk($path)
{
// Add the albumsElement to our root element and write to disk
$xmlDoc->AppendChild($albumsElement);
$xmlDoc->Save($path);
}
AddImage("Image One", "21/04/07", "c1.jpg", "c1.jpg", "A test image for this purpose.");
WriteToDisk(@"gallery.xml");
?>
<?xml version="1.0" encoding="iso-8859-1"?>
<gallery>
<!-- configure the gallery in this xml-node -->
<config>
<!-- set the title of the album -->
<title>YBC PHOTOS!</title>
<!-- set the location of the thumbnails relative to the gallery.swf -->
<thumbnail_dir>images/thumbs/</thumbnail_dir>
<!-- set the actlocation of the actual high-res images relative to the gallery.swf -->
<image_dir>images/big/</image_dir>
<!-- the time interval for each image to display, this value is in seconds
default value : 5
-->
<slideshow_interval>5</slideshow_interval>
<!-- pause slideshow at start
default value : false
-->
<pause_slideshow>false</pause_slideshow>
<!-- set true if you want the application to scale the images while using RSS feeds
default value : true
-->
<rss_scale_images>true</rss_scale_images>
<!-- set the path of the mp3 file that should loop as a background music while playing the slideshow.
default value : none
-->
<background_music>Im_Still_Here.mp3</background_music>
<!-- percentage of the volume to set while playing the music
default value : 50
-->
<background_music_volume>50</background_music_volume>
<!-- add links to images, and allow the views to click on images from flickr, picasa,and
view the page where the actual image is found.
If you dont want views to visit the picasa, or flickr or other sites keep this value false.
default value : false
-->
<link_images>false</link_images>
<!--
Photographers will like to disable printscreen for their pictures
to increase the security of their photographs.
Set this value to true if you wish to disable print screen in the application.
While the application is running the print screen option will be completely disabled in
all other applications that the visitor is using.
default value : false
-->
<disable_printscreen>false</disable_printscreen>
</config>
<!-- this node contains all the albums -->
<albums>
<album title="Test Gallery" description="This is a testing gallery.">
<image title="Test Image One" date="21/04/07" thumbnail="c1.jpg" image="c1.jpg">A perfect shot of a white tiger walking in the woods</image>
<image title="Test Image Two" date="29/05/07" thumbnail="c2.jpg" image="c2.jpg"> This beast scared us by giving us a really sudden shot.</image>
</album>
<album title="Test Gallery2" description="This is a testing gallery.">
<image title="Test Image Three" date="21/04/07" thumbnail="c3.jpg" image="c3.jpg">A perfect shot of a white tiger walking in the woods</image>
<image title="Test Image Four" date="29/05/07" thumbnail="c4.jpg" image="c4.jpg"> This beast scared us by giving us a really sudden shot.</image>
</album>
</albums>
<!-- language support added in v 1.0b -->
<language>
<string id="please wait" value="Please wait" />
<string id="loading" value="Loading" />
<string id="previous page" value="Previous Page" />
<string id="page % of %" value="Page % of %" />
<string id="next page" value="Next Page" />
</language>
</gallery>
I'm trying to develop a backend for a gallery that uses Flash and XML. I've come to the stage of getting very angry with myself that I cannot get this to work, I've tried so many different ways and ideas and tutorials and snippets to try and get this to work, but nothing.
I did discover this http://www.kirupa.com/net/writingXML_pg4.htm (http://www.kirupa.com/net/writingXML_pg4.htm) and thought what a great resource exactly what I want, except it's for .NET. So I went about transferring it to PHP. But alas Epic Failure!
Just need some help on what’s wrong here I've posted both the XML document and the php code. Basically I'm trying to add images to an album. Once I get this working (with your help) I will start on the form to submit the pictures and also work on another php class to create a new album, instead of just having the 2 that are in the XML file. You will understand this when you see the XML file.
I'll keep this a working project on here for others who are in the same boat. I feel using Flash and XML for galleries is great however manually entering data is not my idea or a complete system.
Thanks
Josh
<?php
$xmldoc = loadXMLDoc('gallery.xml');
function AddImage($title, $date, $thumbnail, $image, $description)
{
//
// Initialize albumsElement if you are adding your first album.
//
$albumsElement = $xmlDoc.GetElementById("album");
//
// Adding and populating the elements
//
$imageElement = xmlDoc.CreateElement("image");
$descriptionElement.InnerText = $description;
$imageElement.AppendChild($descriptionElement);
$imageAttribute = xmlDoc.CreateAttribute("title");
$imageElement.SetAttributeNode($imageAttribute);
$imageAttribute.Value = $title;
$imageAttribute = xmlDoc.CreateAttribute("date");
$imageElement.SetAttributeNode($imageAttribute);
$imageAttribute.Value = $date;
$imageAttribute = xmlDoc.CreateAttribute("thumbnail");
$imageElement.SetAttributeNode($imageAttribute);
$imageAttribute.Value = $thumbnail;
$imageAttribute = xmlDoc.CreateAttribute("image");
$imageElement.SetAttributeNode($imageAttribute);
$imageAttribute.Value = $image;
$albumsElement.AppendChild($imageElement);
}
function WriteToDisk($path)
{
// Add the albumsElement to our root element and write to disk
$xmlDoc->AppendChild($albumsElement);
$xmlDoc->Save($path);
}
AddImage("Image One", "21/04/07", "c1.jpg", "c1.jpg", "A test image for this purpose.");
WriteToDisk(@"gallery.xml");
?>
<?xml version="1.0" encoding="iso-8859-1"?>
<gallery>
<!-- configure the gallery in this xml-node -->
<config>
<!-- set the title of the album -->
<title>YBC PHOTOS!</title>
<!-- set the location of the thumbnails relative to the gallery.swf -->
<thumbnail_dir>images/thumbs/</thumbnail_dir>
<!-- set the actlocation of the actual high-res images relative to the gallery.swf -->
<image_dir>images/big/</image_dir>
<!-- the time interval for each image to display, this value is in seconds
default value : 5
-->
<slideshow_interval>5</slideshow_interval>
<!-- pause slideshow at start
default value : false
-->
<pause_slideshow>false</pause_slideshow>
<!-- set true if you want the application to scale the images while using RSS feeds
default value : true
-->
<rss_scale_images>true</rss_scale_images>
<!-- set the path of the mp3 file that should loop as a background music while playing the slideshow.
default value : none
-->
<background_music>Im_Still_Here.mp3</background_music>
<!-- percentage of the volume to set while playing the music
default value : 50
-->
<background_music_volume>50</background_music_volume>
<!-- add links to images, and allow the views to click on images from flickr, picasa,and
view the page where the actual image is found.
If you dont want views to visit the picasa, or flickr or other sites keep this value false.
default value : false
-->
<link_images>false</link_images>
<!--
Photographers will like to disable printscreen for their pictures
to increase the security of their photographs.
Set this value to true if you wish to disable print screen in the application.
While the application is running the print screen option will be completely disabled in
all other applications that the visitor is using.
default value : false
-->
<disable_printscreen>false</disable_printscreen>
</config>
<!-- this node contains all the albums -->
<albums>
<album title="Test Gallery" description="This is a testing gallery.">
<image title="Test Image One" date="21/04/07" thumbnail="c1.jpg" image="c1.jpg">A perfect shot of a white tiger walking in the woods</image>
<image title="Test Image Two" date="29/05/07" thumbnail="c2.jpg" image="c2.jpg"> This beast scared us by giving us a really sudden shot.</image>
</album>
<album title="Test Gallery2" description="This is a testing gallery.">
<image title="Test Image Three" date="21/04/07" thumbnail="c3.jpg" image="c3.jpg">A perfect shot of a white tiger walking in the woods</image>
<image title="Test Image Four" date="29/05/07" thumbnail="c4.jpg" image="c4.jpg"> This beast scared us by giving us a really sudden shot.</image>
</album>
</albums>
<!-- language support added in v 1.0b -->
<language>
<string id="please wait" value="Please wait" />
<string id="loading" value="Loading" />
<string id="previous page" value="Previous Page" />
<string id="page % of %" value="Page % of %" />
<string id="next page" value="Next Page" />
</language>
</gallery>