title: dynamic image gallery
body: <p>Hey all, my first post :D</p>
  
  <p>Problem:</p>
  
  <p>I'm trying to make a template gallery, not a slide show, which i can easily reuse on multiple sites.<br>
  Mostly for quick folio sites, where the owner wont know how to update the code to add pictures.</p>
  
  <p>It needs to read all of the image files from a selected directory. (jpg, gif, png, bmp)
  It needs to be able to update content without any code changes.  (dynamic load from folder)
  It needs to write out img tags to the viewed page. (using JavaScript for customization/css?)</p>
  
  <p>The set of img tags output from the php/JavaScript need to be thumbnails which when clicked will link to the full def pictures, this can probably be handled with JavaScript when making the links initially.</p>
  
  <p>Progress:</p>
  
  <p>I found a php script that will read the files from a folder and save the urls to an array for use in JavaScript.
  However the code used to display the picture is done as a single block slide show, where as i need it to post all images separately not just replace the src of the same image.</p>
  
  <p>Example:  </p>
  
  <blockquote>
    <p>root/index.htm - pastebin[.]com/m52568ed5<br>
    root/images/getimages.php - pastebin[.]com/f5395a572<br>
    root/images/pic01.png<br>
    root/images/pic03.jpg<br>
    root/images/asdfs.gif  </p>
  </blockquote>
  
  <p>So how do i get JavaScript to loop through the galleryarray[curimg] and write out my links?</p>
  
  <p>I got this far, and got stuck.</p>
  
  <pre><code>function rotateimages(){
   // document.getElementById("slideshow").setAttribute("src", "res/gallery/painting/"+galleryarray[curimg])
   // curimg=(curimg&lt;galleryarray.length-1)? curimg+1 : 0
   for (curimg=1;curimg!=0;curimg++;) {
   document.write("&lt;div&gt;&lt;img class='gallery' src='" + galleryarray[curimg] + "' /&gt;&lt;/div&gt;")
   }
  }
  </code></pre>
  
  <p>Thanks in advance, Braden.</p>
  
  <hr>
  
  <p>EDIT: 
  heres my sandbox to show whats going on</p>
  
  <blockquote>
    <p>-EDIT: removed link</p>
  </blockquote>
  
  <p>No matter how i change the output per item for example if i replace the whole section with a simple echo all i ever get is the following:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;My Gallery&lt;/title&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;div id="gallery"&gt;&lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Seems like it gets stuck when it tries to run the 'foreach()'</p>
  
  <p>Heres the current php:</p>
  
  <pre><code>&lt;?php
  
  function getDirTree($dir,$p=true) {
      $d = dir($dir);$x=array();
      while (false !== ($r = $d-&gt;read())) {
          if($r!="."&amp;&amp;$r!=".."&amp;&amp;(($p==false&amp;&amp;is_dir($dir.$r))||$p==true)) {
                  $x[$r] = (is_dir($dir.$r)?array():(is_file($dir.$r)?true:false));
          }
      }
  
      foreach ($x as $key =&gt; $value) {
          if (is_dir($dir.$key."/")) {
                  $x[$key] = getDirTree($dir.$key."/",$p);
          }
      }
  
      ksort($x);
      return $x;
  }
  
  $tree = getDirTree("./res/gallery/");
  
  echo '&lt;div id="gallery"&gt;';
  
  foreach($tree as $element =&gt; $eval) {
      if (is_array($eval)) {
  
          foreach($eval as $file =&gt; $value) {
                  if (strstr($file, "jpg")) {
                          $file = 'res/gallery/'.$element.'/'.$file;
                          echo 'test'; //test//echo '&lt;a href="'.$file.'"&gt;test&lt;/a&gt;'; //test// &lt;img class="gallery" src="'.$file.'" alt="'.$file.'"/&gt;&lt;/a&gt;';
                  }
          }
  
  
      }
  }
  echo '&lt;/div&gt;';
  </code></pre>
  
  <p>considering as i have Never done php before i started this, i think im doing ok.</p>