Last updated: May 2018 | File count: 32
<div class="row"> <div class="card-columns">
<!--begin dynamic gallery-->
<?php
$directory = 'thumbnails/folder'; //path to thumbnails
$link = 'slides/folder'; //path to full-sized images
$allowed_types = array('jpg','jpeg','png');
$aFiles = array();
$dir_handle = @opendir($directory) or die("There is an error with your image directory!");
while ($file = readdir($dir_handle)) //traverse through directory
{
if($file=='.' || $file == '..') continue; //skip links to parent directories
$file_parts = explode('.',$file); //split file parts and put each into an array
$ext = strtolower(array_pop($file_parts)); //last part is extension
$title = implode('.',$file_parts); //whats left is filename
$title = htmlspecialchars($title); //make the filename html-safe
if(in_array($ext,$allowed_types))
{
$aFiles[] = $file;
}
}
closedir($dir_handle); //close directory
natsort($aFiles); // natural sort filenames
$aFiles = array_reverse($aFiles); //display in reverse order
$i=0; //loop
foreach ($aFiles as $file) { //repeat as before
$file_parts = explode('.',$file);
$ext = strtolower(array_pop($file_parts));
$title = implode('.',$file_parts);
$title = htmlspecialchars($title);
echo '
<div class="card">
<a data-fancybox="gallery" class="fancybox" data-slide="'.++$i.'" href="'.$link.'/'.$file.'"><img class="img-fluid" alt="'.$title.'" src="'.$directory.'/'.$file.'"></a></div>';
}
?>
</div><!--end gallery->