Created
July 29, 2017 22:51
-
-
Save michvaldes001/e8bf2255e9a2c347cd02af3c580dec81 to your computer and use it in GitHub Desktop.
A quick and simple photo gallery.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Requires LightBox to work. | |
//Example at https://valdestechtravel.net/gallery/?root_dir=gallery_main&work_dir=Washington&columns=3 | |
echo ' | |
<html> | |
<head> | |
<link rel="stylesheet" href="css/lightbox.min.css"> | |
<style> | |
body | |
{ | |
background-color: #333333; | |
color: #ffffff; | |
float: left; | |
} | |
<style> | |
ul.grid | |
{ | |
list-style: none; | |
font-size: 0px; | |
margin-left: -2.5%; | |
} | |
ul.grid li | |
{ | |
display: inline-block; | |
padding: 5px; | |
margin: 0 0 2.5% 2.5%; | |
background: #fff; | |
border: 1px solid #ddd; | |
font-size: 16px; | |
font-size: 1rem; | |
vertical-align: top; | |
box-shadow: 0 0 5px #ddd; | |
box-sizing: border-box; | |
-moz-box-sizing: border-box; | |
-webkit-box-sizing: border-box; | |
} | |
ul.grid li img | |
{ | |
max-width: 100%; | |
height: auto; | |
margin: 0 0 5px; | |
} | |
ul.grid li h3 | |
{ | |
margin: 0 0 5px; | |
} | |
ul.grid li p | |
{ | |
font-size: .9em; | |
line-height: 1.5em; | |
color: #999; | |
} | |
ul.grid.columns-2 li | |
{ | |
width: 47.5%; | |
} | |
ul.grid.columns-3 li | |
{ | |
width: 30.83%; | |
} | |
ul.grid.columns-4 li | |
{ | |
width: 22.5%; | |
} | |
@media (max-width: 480px) | |
{ | |
ul.grid-nav li | |
{ | |
display: block; | |
margin: 0 0 5px; | |
} | |
ul.grid-nav li a | |
{ | |
display: block; | |
} | |
ul.grid li | |
{ | |
width: 100% !important; | |
margin: 0 0 20px; | |
} | |
} | |
</style> | |
</head> | |
<body> | |
'; | |
class MAIN_GALLERY | |
{ | |
//main function | |
public function main_gallery_display($root_dir, $work_dir, $columns) | |
{ | |
if ($work_dir == NULL) | |
{ | |
echo 'No Work Directory Specified'; | |
} | |
elseif ($root_dir == NULL) | |
{ | |
echo 'No Root Directory Specified'; | |
} | |
else | |
{ | |
$this->show_photos($root_dir, $work_dir, $columns); | |
} | |
} | |
//display photos | |
private function show_photos($root_dir, $work_dir, $columns) | |
{ | |
if ($columns > 4 || $columns < 2) | |
{ | |
$columns = 2; | |
} | |
echo '<ul class="grid columns-' . $columns . '"">'; | |
foreach(glob($root_dir . '/' . $work_dir . '/*.JPG') as $photos) | |
{ | |
$photo_names = basename($photos); | |
echo "<li><a href = '" . $root_dir . "/" . $work_dir . "/". $photo_names . "' data-lightbox='" . $work_dir. "' data-title='" . $work_dir . "'><img src ='" . $root_dir . "/" . $work_dir . "/thumbnail/". $photo_names . "'></a></li>"; | |
} | |
echo '<br><button type="button" onclick="history.back();">Back</button>'; | |
} | |
} | |
$root_dir = $_GET['root_dir']; | |
$work_dir = $_GET['work_dir']; | |
$columns = $_GET['columns']; | |
$initiate = new MAIN_GALLERY(); | |
$initiate->main_gallery_display($root_dir, $work_dir, $columns); | |
//Lightbox JS script include | |
echo ' | |
<script src="js/lightbox-plus-jquery.min.js"></script> | |
</body> | |
</html>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment