title: Need a lightbox gallery that calls from image folder, no thumbnails and opens from one button click?
body: <p>Thank you all in advance for the outstanding help I know I will get, you have never let me down.</p>
  
  <p>I need to create an image gallery that opens from a button click..no problem (<a href="http://bcreativeservices.com/" rel="nofollow">http://bcreativeservices.com/</a>), I have that down. My problem is that I need the gallery to be able to call images from a folder without each image having to be listed in the page. We are looking for the client to be able to upload or delete image from one folder and not have to update the "gallery" code.</p>
  
  <p>I tried working out this example (<a href="http://jdmweb.com/creating-a-simple-image-gallery-with-php-jquery" rel="nofollow">http://jdmweb.com/creating-a-simple-image-gallery-with-php-jquery</a>) , which seemed perfect for what I am needing, but either the tutorial is leaving something out, or it assumes a level of knowledge and skill that I do not possess, which is the more likely answer.  </p>
  
  <p>This is the page I have been trying to work it out with: <a href="http://fosterfence.petropages-hosting.com/gallery.php" rel="nofollow">http://fosterfence.petropages-hosting.com/gallery.php</a>  I am just using the gallery button image in the middle of the page to work with, in the end it will be the gallery button in the header that I need to link. I just need to get it working first. I don't get any error message, no syntax errors, but I am missing something.</p>
  
  <p>Question: What am I doing incorrectly with the example I have started working with? This is my page: </p>
  
  <pre><code> &lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Industrial Fencing | Chain Link Fence | Security Fencing - Foster Fence, Ltd.&lt;/title&gt;
          &lt;meta name="keywords" content="Industrial Fencing,Chain Link Fence,Security Fencing"&gt;
          &lt;meta name="description" content="Foster Fence is a professional fencing contractor that serves industrial, government and commercial markets in the Greater Houston Metropolitan area, Louisiana and the Gulf Coast. Foster Fence carries an extensive range of fencing products ranging from chain link and ornamental iron fencing to security fences and gates. "&gt;
          &lt;meta name="author" content="PetroPages Creative Services"&gt;
          &lt;meta name="geo.region" content="US-TX" /&gt;
          &lt;meta name="geo.placename" content="Houston" /&gt;
          &lt;meta name="geo.position" content="29.861615;-95.138465" /&gt;
          &lt;meta name="ICBM" content="29.861615, -95.138465" /&gt;
  
  &lt;?php
  //imgallery PHP Class
  include("imgallery.php");
  ?&gt;
  
  &lt;!--Scripts (jQuery + LightBox Plugin + imgallery Script)--&gt;
  &lt;script type="text/javascript" src="js/jquery-1.11.1.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/jquery.lightbox.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/imgallery.js"&gt;&lt;/script&gt;
  
  &lt;!--CSS (LightBox CSS + imgallery CSS)--&gt;
  &lt;link rel="stylesheet" type="text/css" href="css/lightbox.css" /&gt;
  &lt;link rel="stylesheet" type="text/css" href="css/imgallery.css" /&gt;
  
  
          &lt;?php include_once("header.php") ?&gt;
  
  
          &lt;div class="content"&gt;
  
  
  
  
  
        &lt;a href="/gallery/ameristar.jpg" class="lightbox" rel="gallery" title="Gallery"&gt;
            &lt;img src="/images/gallery_btn.png" alt="image1.jpg" /&gt;
          &lt;/a&gt;
  
  
  
      &lt;/div&gt;
  
  
  
          &lt;/div&gt;
  
  
  
          &lt;?php include_once("footer.php") ?&gt;
  </code></pre>
  
  <p>This is the file that calls the images from the gallery folder and writes the lightbox: </p>
  
  <pre><code>&lt;?php
  
  class ImgGallery {
  
    //=======================================//
    //==========&gt; Class Variables &lt;==========//
    //=======================================//
    private $thumbsize;   //Size of the image thumbnail
    private $maxsize;     //Size of the image
    private $folderpath;  //Path to the folder where the images are stored
    private $elements;
  
  
  //=======================================================================================//
  //================================= Core Methods ========================================//
  //=======================================================================================//
  
  
    //=======================================//
    //============&gt; Constructor &lt;============//
    //=======================================//
    public function __construct(
      $thumbsize=96, //Change this to match your thumbnail size
      $maxsize=640, //Change this to match your maximum image size
      $folderpath="/gallery", //Change this to match your folder path
      $elements=array()
    ){
      $this-&gt;thumbsize=$thumbsize;
      $this-&gt;maxsize = $maxsize;
      $this-&gt;folderpath = $folderpath;
      $this-&gt;elements = $elements;
    }
  
  
    //========================================//
    //=====&gt; List the images to include &lt;=====//
    //========================================//  
    public function getImageArray(){
      //Tell the class to look for images inside this folder
      $path = $this-&gt;folderpath.'/{*.jpg,*.gif,*.png}';
      $imgarray=glob($path,GLOB_BRACE)?glob($path,GLOB_BRACE):array();
      return $imgarray; //Return the found images
    }
  
    //=========================================//
    //=====&gt; Add an image to the gallery &lt;=====//
    //=========================================//  
    public function addImage($src){
      $elements = $this-&gt;elements;
      $elements[] = $src;
      $this-&gt;elements = $elements;
    }
  
    //==========================================//
    //===&gt; Add all the images from a folder &lt;===//
    //==========================================//  
    public function loadImages(){
      $imgarray = $this-&gt;getImageArray();
      if(!empty($imgarray)){foreach($imgarray as $img){ $this-&gt;addImage($img); }}
    }
  
    //=========================================//
    //==&gt; Write the markup for the gallery &lt;===//
    //=========================================//    
    public function display($showit=1){
      $markup='
      &lt;div id="easyimgallery"&gt;
        &lt;ul&gt;';
        if(!empty($this-&gt;elements)){foreach($this-&gt;elements as $img){
          $thumb=$this-&gt;getImageThumbnail($img);
          $maxsize=$this-&gt;getMaxImage($img);
          $imgname=end(explode("/",$img));
          $markup.='&lt;li&gt;&lt;a href="'.$maxsize.'" class="lightbox" title="'.$imgname.'"&gt;
            &lt;img src="'.$thumb.'" alt="'.$imgname.'" /&gt;
          &lt;/a&gt;&lt;/li&gt;';
        }}
        $markup.='
        &lt;/ul&gt;
      &lt;/div&gt;';
      if($showit==1){ echo $markup; }
      return $markup;
  }
  
    //=========================================//
    //====&gt; Easy call to set everything up &lt;===//
    //=========================================//    
    public function getPublicSide(){
      $gallery = new ImgGallery();
      $gallery-&gt;loadImages();
      $gallery-&gt;display();
    }
  
    //=========================================//
    //=====&gt; Create the image thumbnail &lt;======//
    //=========================================//    
    public function getImageThumbnail($src){
      $size=$this-&gt;thumbsize;
      $imgSrc = $src;  
  
      //cached img
      $cachepath = $this-&gt;folderpath.'/cache/'.$size.'x'.$size.''.str_replace("/","~",$imgSrc);   
      if(file_exists($cachepath)){ return substr($cachepath,1); } //If cached, return right away
      else {  //Create the thumbnail
          //getting the image dimensions   
          list($width, $height, $type, $att) = getimagesize($imgSrc); 
  
          switch($type) {//saving the image into memory (for manipulation with GD Library)   
              case 1: $myImage = imagecreatefromgif($imgSrc); break;
              case 2: $myImage = imagecreatefromjpeg($imgSrc); break;
              case 3: $myImage = imagecreatefrompng($imgSrc); break;      
          }
          if($width&gt;$size || $height&gt;$size) {
              //setting the crop size   
              if($width &gt; $height) $biggestSide = $width;    
              else $biggestSide = $height;    
              //The crop size will be half that of the largest side 
              $cropPercent = .5;    
              $cropWidth   = $biggestSide*$cropPercent;    
              $cropHeight  = $biggestSide*$cropPercent;    
          }
          else { $cropWidth   = $width; $cropHeight  = $height; }
  
          //getting the top left coordinate   
          $c1 = array("x"=&gt;($width-$cropWidth)/2, "y"=&gt;($height-$cropHeight)/2);   
  
          // Creating the thumbnail    
          $thumbSize = $size;    
          $thumb = imagecreatetruecolor($thumbSize, $thumbSize);    
          imagecopyresampled($thumb, $myImage, 0, 0, $c1['x'], $c1['y'], $thumbSize, $thumbSize, $cropWidth, $cropHeight);
  
          //final output 
          $this-&gt;cachePicture($thumb,$cachepath);   
          imagedestroy($thumb);  
          return substr($cachepath,1);
      }
    }
  
    //=========================================//
    //======&gt; Create the max size image &lt;======//
    //=========================================//    
    public function getMaxImage($src){
      //Get the parameters
      $filename=$src;
      $size=$this-&gt;maxsize;
      $width=$size;
      $height=$size;
  
      //Get the cache path
      $cachepath = $this-&gt;folderpath.'/cache/'.$size.'x'.$size.''.str_replace("/","~",$filename);
  
      if(file_exists($cachepath)){ return substr($cachepath,1); } //If cached, return right away
      else //Create the image
      {
          // Compute the new dimensions
          list($width_orig, $height_orig, $type, $att) = getimagesize($filename);
          if($width_orig&gt;$size || $height_orig&gt;$size) {
              $ratio_orig = $width_orig/$height_orig;
              if ($width/$height &gt; $ratio_orig) { $width = $height*$ratio_orig; } 
              else { $height = $width/$ratio_orig; }
          }
          else { $width=$width_orig; $height=$height_orig; }
  
          //Create the image into memory (for manipulation with GD Library)
          $step1 = imagecreatetruecolor($width, $height);
          switch($type) {   
              case 1: $image = imagecreatefromgif($filename); break;
              case 2: $image = imagecreatefromjpeg($filename); break;
              case 3: $image = imagecreatefrompng($filename); break;          
          }
  
          //Resize the image, save it, and return it
          imagecopyresampled($step1, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);     
          $this-&gt;cachePicture($step1,$cachepath);  
          ImageDestroy($step1); 
          return substr($cachepath,1);
  
      }
    }
  
    //=============================================//
    //==&gt; Save the dynamically created pictures &lt;==//
    //=============================================//    
    public function cachePicture($im,$cachepath){
      if(!is_dir(dirname($cachepath))){ mkdir(dirname($cachepath)); }
      if (function_exists("imagepng")) { imagepng($im,$cachepath); }
      elseif (function_exists("imagegif")) { imagegif($im,$cachepath); }
      elseif (function_exists("imagejpeg")) { imagejpeg($im,$cachepath, 0.5); }
      elseif (function_exists("imagewbmp")) { imagewbmp($im,$cachepath);} 
      else { die("Doh ! No graphical functions on this server ?"); }
      return $cachepath;      
    }
  
    //=========================================================//
    //=&gt; Used for debugging to see what the gallery contains &lt;=//
    //=========================================================//    
    public function trace(){
      highlight_string(print_r($this,true));
    }
  
  }  
  
  ?&gt;
  </code></pre>