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 .= ' '; } # 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; ?>
0 comments:
Post a Comment