View Full Version : How to use PHP form to amend XML for gallery

12-05-2008, 07:38 AM

Please let me start by saying I'm by no means anywhere near been competent enough to really work with PHP, however I seem to understand the basics and especially with all the help and support all over the internet for PHP it has made it easier to try and create something a little more complicated then I would normally.

Hence the position I'm in now, I'm basically trying to create a backend for a FLASH/XML gallery that I downloaded. So Iíve tried to create a form that will upload a picture and create a thumbnail. I also need though to get the form to produce elements of the XML that goes with the gallery. I have 5 files (code bellow):

I've got so far with this project and I have now come to the stage that I need a little more help than just searching the net for answers.

What Iím asking is really this, how oh how do I publish the information from the form to the xml file! (I'm trying I suppose too many ways, giving the user the ability to add images to an already existing gallery and adding images to an already existing gallery)

Thank you for your time,




$final_width_of_image = 75;
$path_to_image_directory = 'images/big/';
$path_to_thumbs_directory = 'images/thumbs/';




function createThumbnail($filename) {

require 'config.php';

if(preg_match('/[.](jpg)$/', $filename)) {
$im = imagecreatefromjpeg($path_to_image_directory . $filename);

$ox = imagesx($im);
$oy = imagesy($im);

$nx = $final_width_of_image;
$ny = floor($oy * ($final_width_of_image / $ox));

$nm = imagecreatetruecolor($nx, $ny);

imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);

if(!file_exists($path_to_thumbs_directory)) {
if(!mkdir($path_to_thumbs_directory)) {
die("There was a problem. Please try again!");

imagejpeg($nm, $path_to_thumbs_directory . $filename);
$tn = '<img src="' . $path_to_thumbs_directory . $filename . '" alt="image" />';
$gallery = 'New Gallery';
$tn .= '<br /><font color="#00CC33">Congratulations. Your image has been successfully uploaded to ' . $gallery . '.</font>';
echo $tn;




require 'config.php';
require 'functions.php';

if(isset($_FILES['fupload'])) {

if(preg_match('/[.](jpg)|(JPG)$/', $_FILES['fupload']['name'])) {

$filename = $_FILES['fupload']['name'];
$source = $_FILES['fupload']['tmp_name'];
$target = $path_to_image_directory . $filename;

move_uploaded_file($source, $target);

else {
$filename = $_FILES['fupload']['name'];
$tn .= '<br /><span class="error">' . $filename . ' is the wrong file type. The image has to be .jpg</span>';
echo $tn;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="" />
<title>Gallery Upload</title>
<style type="text/css">
.error {color: #FF0000}
.success {colour: #00CC33}

<h1>Upload an Image to Gallery!</h1>
<form action="<?php print $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">
<p>Select Gallery to Upload Image:</p>
<label>Old Gallery:
<input name="GallerySel" type="radio" id="GallerySelRad1" value="oldGall" checked="checked" />
$doc = new DOMDocument();
$doc->load( 'gallery.xml' );

$albums = $doc->getElementsByTagName( "album" );
echo "<select>";
foreach( $albums as $album )

$albumlist = $album->getAttribute('title');

echo "<option name='$albumlist'>$albumlist</option>";
echo "</select>";
<br />
New Gallery:
<input type="radio" name="GallerySel" value="newGall" id="GallerySelRad2" />
<input type="text" name="imageGallery" id="newgallery" />
<br />
<p>Image Date (dd/mm/yyyy):
<input name="imageDate" type="text" id="imageDate" size="10" maxlength="10" />
<p>Image Description:
<input name="imageDesc" type="text" id="imageDesc" size="70" maxlength="70" />
<input type="file" name="fupload" />
<input type="submit" value="Go!" />




//Creates XML string and opens XML document using the DOM
$dom = new DomDocument();
//find element - <album>
$albums = $dom->getElementsByTagName("album");

//add <image> element to <album>
$image = $dom->appendChild($dom->createElement('image'));

//add title attribute to <image>
$image->appendChild($dom->setAttribute('title', 'test'));

//add date attribute to <image>
$image->appendChild($dom->setAttribute('date', '11/10/2008'));

//add thumbnail attribute to <image>
$image->appendChild($dom->setAttribute('thumbnail', 'c3.jpg'));

//add image attribute to <image>
$image->appendChild($dom->setAttribute('image', 'c3.jpg'));

//add <image> text node element to <image>
$image->appendChild($dom->createTextNode('This was a great image!'));

//generate xml
$dom->formatOutput = true; // set the formatOutput attribute of
// domDocument to true
// save XML as string or file
$test1 = $dom->saveXML(); // put string in test1
$dom->save('gallery.xml'); // save as file


<?xml version="1.0" encoding="iso-8859-1"?>


Author : G.S.Navin Raj Kumar
URL : http://dezinerfolio.com
Date : 14-June-2007
Version : 1.0b


<!-- configure the gallery in this xml-node -->

<!-- set the title of the album -->
<title>YBC PHOTOS!</title>

<!-- set the location of the thumbnails relative to the gallery.swf -->

<!-- set the actlocation of the actual high-res images relative to the gallery.swf -->

<!-- the time interval for each image to display, this value is in seconds
default value : 5

<!-- pause slideshow at start
default value : false

<!-- set true if you want the application to scale the images while using RSS feeds
default value : true

<!-- set the path of the mp3 file that should loop as a background music while playing the slideshow.
default value : none

<!-- percentage of the volume to set while playing the music
default value : 50

<!-- 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

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


<!-- this node contains all the 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>

<!-- language support added in v 1.0b -->

<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" />


12-08-2008, 03:35 AM

I've seen it done, i'm just not getting it right. What am I doing wrong?