Auto create gallery for JonDesign’s Smooth Gallery

This is something I wrote to make my life easier adding images on the JDGallery. It automatically scans the directory and creates the div section (where gallery and images are defined). Simply replace the following section.
<div class="content">
<div id="myGallerySet">
with the output of the code below
$path = "gallery"; //path to scan for folders/images
//couple of things
//thumbnails must be named {filename}_thumb.{extension}
//extension of file is limited to 3 character like jpg, gif, not jpeg, etc.
//sorry, got no time to enhance it, so you can copy and modify as needed, it's free.
//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");
echo "Copy Paste the code below.<br><br>";
echo "<tt>&lt;div class="content"&gt;<br>&lt;div id="myGallerySet"&gt;<br><br>";
echo "&lt;/div&gt;<br>&lt;/div&gt;</tt>";
function list_dir($dir_handle,$path)
	$countgallery = 1;
	$countimages = 1;
	//running the while loop
    while (false !== ($file = readdir($dir_handle))) {
        $dir =$path.'/'.$file;
		if(is_dir($dir) && $file != '.' && $file !='..' )		
			$handle = @opendir($dir) or die("unable to open file $file");
			echo "&lt;div id="gallery$countgallery" class="galleryElement"&gt;<br>&lt;h2&gt;$file&lt;/h2&gt;<br><br>";
            list_dir($handle, $dir);
			echo "&lt;/div&gt;<br><br>";
			$countimages = 1;
		elseif($file != '.' && $file != '..' && substr($dir, -9, 5) != 'thumb')
			$mainfilename = $dir;
			$thumbfilename = substr($dir, 0, -4) . "_thumb.jpg";
			echo "&lt;div class="imageElement"&gt;<br>&lt;h3&gt;Item $countimages Title&lt;/h3&gt;<br>&lt;p&gt;Item $countimages Description&lt;/p&gt;<br>&lt;a href="#" title="open image" class="open"&gt;&lt;/a&gt;<br>&lt;img src="$mainfilename" class="full" /&gt;<br>&lt;img src="$thumbfilename" class="thumbnail" /&gt;<br>&lt;/div&gt;<br>";
    //closing the directory

Leave a Reply

Your email address will not be published. Required fields are marked *