I'm trying to build a simple gallery from a directory. I have this scenario:
- 2013 <-- directory
-- Album 1 <-- directory
-- image1.jpg <-- file
-- image2.jpg
-- image3.jpg
-- Album 2
-- image1.jpg
- 2014
-- Album 1
-- image1.jpg
-- image2.jpg
-- Album 2
-- image1.jpg
I tought that DirectoryIterator can simply do this, but I can't figure out to get it work and call the functions.
So far:
Print a list of years
function listYears(){
$basefolder = "gallery/";
foreach (new DirectoryIterator($basefolder) as $fileInfo) {
if($fileInfo->isDot()) continue;
if($fileInfo->isFile()) continue;
echo '<a href="index.php?year='. $fileInfo->getFilename() .'">'. $fileInfo->getFilename() .'</a><br>';
}
true;
}
Print a list of the Albums in the selected year
function listAlbums($year){
$basefolder = 'gallery/'. $year;
foreach (new DirectoryIterator($basefolder) as $fileInfo) {
if($fileInfo->isDot()) continue;
if($fileInfo->isFile()) continue;
echo '<a href="index.php?year='. $year .'&album='. $fileInfo->getFilename() .'"></a>';
}
true;
}
And finally get the images
function getImages($year,$album){
$basefolder = "gallery/";
foreach (new DirectoryIterator($basefolder) as $fileInfo) {
if($fileInfo->isDot()) continue;
if($fileInfo->isDir()) continue;
echo '<img src="'. $basefolder.''. $year.'/'. $album .'/'. $fileInfo->getFilename() .'">';
}
true;
}
So, i'm trying to do something like
www.site.com/gallery.php?year=2014
and view the albums of 2014, so you can choose
www.site.com/gallery.php?year=2014&album=album_name
and view the photos from that album.
Even better would be
www.site.com/gallery/2014/album_name
Thank you.
You can use folioGallery It's a php photo gallery which uses your file system to generate gallery.
downlaod link for same : http://www.foliopages.com/php-jquery-ajax-photo-gallery-no-database