Showing pics from a camera

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Showing pics from a camera

Post 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?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
schwarzerosen
Forum Newbie
Posts: 3
Joined: Fri Jun 26, 2009 10:45 pm

Re: Showing pics from a camera

Post 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.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: Showing pics from a camera

Post 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.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply