Skip to content

Instantly share code, notes, and snippets.

@zbee
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zbee/67e2968b1e5384d16a18 to your computer and use it in GitHub Desktop.
Save zbee/67e2968b1e5384d16a18 to your computer and use it in GitHub Desktop.
A simple little file to be set at the root of a directory with many images and subdirectories when enables easy viewing of images and navigation of directories.
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<Br>
<?php
function check($array, $input) {
foreach($array as $value) {
if(strpos($input, $value) !== false) {
return true;
return false;
}
$up = isset($_GET['view']) ? count(explode("/", $_GET['view']))-2 >= 0 ? "<li><a href='?view=" . explode("/", $_GET['view'])[count(explode("/", $_GET['view']))-2] . "'>Up</a></li>" : "<li><a href='./'>Up</a></li>" : "";
$bod = "";
$head = "<ol class='breadcrumb'>" . $up;
$c = 0;
$t = 0;
if (!isset($_GET['view'])) {
$fins = scandir("./");
foreach($fins as $i) {
if (is_dir("./" . $i) && strlen($i) > 2) {
$head .= "<li><a href='?view=" . $i . "'>" . $i;
} elseif (is_file("./".$i)) {
if ($c == 0) { $bod .= '<div class="row">'; }
if (strpos($i,'.webm') !== false || strpos($i,'.mp4') !== false) {
$c += 1;
$t += 1;
$bod .= "<div class='col-xs-12 col-md-4'><video src='http://localhost/".$i."' style='width:100%' onMouseOver='this.play()' onMouseOut='this.pause()' onclick='this.pause()' loop></video></div>";
} elseif (check([".png", ".gif", ".jpg", ".jpeg", ".jpe", ".jif", ".jfif", ".jfi", ".jp2", ".j2k", ".jpf", ".jpx", ".jpm", ".mj2"], $i)) { //JPEG, JPEG 2000, GIF, PNG (all supported by GC and FF)
$c += 1;
$t += 1;
$bod .= '<div class="col-xs-12 col-md-4"><img style="width:100%" src="http://localhost/'.$i.'"></div>';
}
if ($c == 3) $bod .= '</div><br>'; $c = 0;
}
}
} else {
if (!is_dir("./" . $_GET['view']))
die("No directory found");
$images = scandir("./" . $_GET['view']);
//shuffle($images);
foreach($images as $i) {
if (is_file("./" . $_GET['view'] . "/" . $i)) {
if ($c == 0) { $bod .= '<div class="row">'; }
if (strpos($i,'.webm') !== false || strpos($i,'.mp4') !== false) {
$c += 1;
$t += 1;
$bod .= "<div class='col-xs-12 col-md-4'><video src='http://localhost/".$_GET["view"]."/".$i."' style='width:100%' onMouseOver='this.play()' onMouseOut='this.pause()' onclick='this.pause()' loop></video></div>";
} elseif (check([".png", ".gif", ".jpg", ".jpeg", ".jpe", ".jif", ".jfif", ".jfi", ".jp2", ".j2k", ".jpf", ".jpx", ".jpm", ".mj2"], $i)) { //JPEG, JPEG 2000, GIF, PNG (all supported by GC and FF)
$c += 1;
$t += 1;
$bod .= '<div class="col-xs-12 col-md-4"><img style="width:100%" src="http://localhost/'.$_GET['view'].'/'.$i.'"></div>';
}
if ($c == 3) { $bod .= '</div><br>'; $c = 0; }
} elseif (is_dir("./" . $_GET['view'] . "/" . $i) && strlen($i) > 2) {
$head .= "<li><a href='?view=" . $_GET['view'] . "/" . $i . "'>" . $i . "</a></li>";
}
}
$head .= "<li>" . $t . " images in this directory</li>";
}
echo $head . "</ol>";
echo $bod;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment