Friday, June 21, 2013

Render XML file for Flash Photo Gallery with php

6/21/2013

Learn how to render dynamic XML files for Flash(or any other) Photo Gallery applications using PHP loops to show the most current data at all times.


This script would be named something like galleryXML.php

This file reads a directory on its own to render the XML file, all you have to do it point it at a folder of images no matter how many are in it, and it will produce nice clean XML nodes for all of the images.




<?php
/* 
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/


# set the content type to xml
header("Content-Type: text/xml");

# Initialize the xmlOutput variable
$xmlBody = '';

# Specify Directory where images are 
$dir = "images/gallery/"; 

# Start XMLBody output
$xmlBody .= ""; 

# open specified directory using opendir() the function
$dirHandle = opendir($dir); 

# Create incremental counter variable
$i = 0;
while ($file = readdir($dirHandle)) 
{ 
      
      # if file is not a folder and if file name contains the string .jpg  

      if(!is_dir($file) && strpos($file, '.jpg'))
      {
        # increment $i by one each pass in the loop
         $i++; 
         $xmlBody .= '

    ' . $i . '
    ' . $dir . '' . $file . '
';
      } # close the if statement

} # End while loop


# close the open directory
closedir($dirHandle); 

$xmlBody .= "";

# output the gallery data as XML file for Flash Photo Gallery
echo $xmlBody; 


?>

helpful? Share this

The Editorial Team of 4everTutorials consists of a group of PHP Professionals.

0 comments:

 

© 2014 4everTutorials. All rights resevered.

Back To Top