Simple Dynamic Image Gallery using PHP
So often you may want to show a little gallery of photos on your blog or website, you have a few choices out there. Choice one would be to just do a down and dirty bit of html, <img src=” etc etc or you could go with a program that creates galleries. Those usually don’t integrate with a site too well, and often are overkill for showing the world your new car, puppy or dinner entrees.
Luckily if you have your FTP program and a few pics handy you can just traverse your directories and spit out the files in code. This can be handy for swapping the files around and even adding more down the road, it will dynamically expand the gallery.
-
$path = “/home/user/public/foldername/”; //path from root
-
if($file == ”.” || $file == ”..” || $file == “index.php” )
-
continue;
-
}
If you want to be slick, make thumbnails with the same name, but tag like tn_ before the image name and put them in another folder, this will allow you to call something like this:
-
echo ‘<a href="$file"><img src="otherfolder/tn_$file" /></a><br />’;
Note: This will also work for files, you can add options to filter only images if you’d like.
Posted in PHP











