Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy How to use PHP form to amend XML for gallery

    Hello,

    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):
    config.php
    functions.php
    upload.php
    xmlprint.php
    gallery.xml

    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,

    Josh

    config.php
    PHP Code:
    <?php

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

    ?>
    functions.php
    PHP Code:
    <?php

    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$im0,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;   
    }  

    ?>
    upload.php
    Code:
    <?php   
      
    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);   
               
            createThumbnail($filename);        
        }   
    	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">   
      
    <head>   
    <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}
    -->
    </style>
    </head>   
      
    <body>   
    <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>
          <p>
            <label>Old Gallery:
            <input name="GallerySel" type="radio" id="GallerySelRad1" value="oldGall" checked="checked" />
            </label>
            <?php
      $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 />
            <label>
            New Gallery:
            <input type="radio" name="GallerySel" value="newGall" id="GallerySelRad2" />
            </label>
            <input type="text" name="imageGallery" id="newgallery" />
            <br />
          </p>
          <p>Image Date (dd/mm/yyyy):
            <input name="imageDate" type="text" id="imageDate" size="10" maxlength="10" />
          </p>
          <p>Image Description:
            <input name="imageDesc" type="text" id="imageDesc" size="70" maxlength="70" />
          </p>
          <p>
            <input type="file" name="fupload" />   
            <input type="submit" value="Go!" />   
            
          </p>
    </form>
    </body>   
    </html>
    xmlprint.php
    PHP Code:
    <?php 

     
    //Creates XML string and opens XML document using the DOM 
     
    $dom = new DomDocument(); 
     
    $dom->load('gallery.xml');
     
    //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 
     
    ?>
    gallery.xml
    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    	<gallery>
    		<!--
    
    					dfGallery
    			
    			Author	: G.S.Navin Raj Kumar
    			URL		: http://dezinerfolio.com
    			Date	: 14-June-2007
    			Version : 1.0b
    
    			PLEASE READ THE DOCUMENTATION CAREFULLY BEFORE MODIFYING THIS FILE.
    
    		-->
    		<!-- 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>
    		</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>

  • #2
    New to the CF scene
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nobody?

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •