Simple photogallery script

It's all done by simply showing the contents of a directory. I've sorted a gallery in 1 folder with 3 subfolders. The name of the folder is the name of the gallery and the 3 subfolders are called "small", "big" and "huge".

First I open my photos directory and display the galleries/directories inside:

PHP:
  1. function getPhotoGalleries() {   
  2.   $handle=opendir("photos");   
  3.   $result ='';
  4.   while ($file = readdir($handle)) {   
  5.     if ($file != "." && $file != "..") {
  6.       $result .= "<li><a href=\"photos.list.php?gallery=$file\">$file</a></li>\n";
  7.     }
  8.   }   
  9.   closedir($handle);   
  10.   return $result;
  11. }

The link will pass along the name of the directory selected and the next function will be called to display the contents of the "small"-directory:

PHP:
  1. function getPhotos($gallery) {
  2.   $handle=opendir("photos/$gallery/small");   
  3.   $result ='';
  4.   while ($file = readdir($handle)) {   
  5.     if ($file != "." && $file != "..") {
  6.       $result .= '<span><a href="photos.details.php?gallery='.$gallery.'&photo='.$file.'"><img width="101" height="101" alt="'.$file.'" src="photos/'.$gallery.'/small/'.$file.'" /></a></span>';
  7.     }
  8.   }   
  9.   closedir($handle);   
  10.   return $result;
  11. }

The next link will go to the detailed page view passing along the name of the gallery and the filename of the photo.

PHP:
  1. echo '<a class="noborder" href="photos/'.$_GET['gallery'].'/huge/'.$_GET['photo'].'"><img width="490" alt="'.$_GET['photo'].'" src="photos/'.$_GET['gallery'].'/big/'.$_GET['photo'].'" /></a>';

The next link will just link directly to the huge image. The important thing is that all the different sizes of the same image has to have the exact same name, or else it will fail.

Leave a Reply

You must be logged in to post a comment.