Page 1 of 1

Showing pics from a camera

Posted: Fri Jun 26, 2009 1:25 pm
by Vegan
I have a bunch of pics from my digital camera, being lazy I do not really want to edit the page with new code every time I press the button.

Anyone got some PHP that Linux likes to scan for pics and makes a bunch of thumbnails and links to the full picture?

Re: Showing pics from a camera

Posted: Fri Jun 26, 2009 11:13 pm
by schwarzerosen

Code: Select all

<?php
  //getting all files of desired extension from the dir using explode
 
  $desired_extension = 'gif'; //extension we're looking for
  $dirname = "images/";
  $dir = opendir($dirname);
  echo '<html><body>';
  while(false != ($file = readdir($dir)))
  {
    if(($file != ".") and ($file != ".."))
    {
      $fileChunks = explode(".", $file);
      if($fileChunks[1] == $desired_extension) //interested in second chunk only
      {      
        echo '<a href="images/'.$file.'" target="_blank"><img src="'.$file.'""></a></br>';
      }
    }
  }
  echo '</body></html>';
  closedir($dir);
?>
 
Taken from http://us.php.net/readdir with some editing. Some image resizing for the thumbnails and changing the extension var. and it should be ready to use.

Re: Showing pics from a camera

Posted: Wed Feb 10, 2010 9:39 pm
by Vegan
Thanks, I am implementing the code in a slightly different way. I carved it up into segments so that I could bolt in into an existing page template. The code example however is ideal for a basic understanding of the code required to generate a page of images from a given folder where the page actually looks for them and display any found automatically.

Thanks as this is very helpful.