3 Bizou - a (french) KISS php image gallery
4 Copyright (C) 2010 Marc MAURICE
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 define('IMAGES_DIR', 'images');
22 $shortPath = $_SERVER["PATH_INFO"];
23 if ($shortPath == '/') $shortPath = '';
24 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
25 if (strpos($shortPath, '..') !== false) die(".. found in url");
27 if (! is_file(IMAGES_DIR.$shortPath)) {
28 header("HTTP/1.1 404 Not Found");
29 die("File Not Found");
32 $scriptPath = $_SERVER["SCRIPT_NAME"];
34 // get all images in an array
37 $files = scandir(IMAGES_DIR.dirname($shortPath));
38 foreach ($files as $file) {
39 $ext = strtolower(substr($file, -4));
40 if ($ext == ".jpg" or $ext == ".png")
44 // find the image position
45 $pos = array_search(basename($shortPath), $images);
46 if ($pos === false) die("Image not found");
48 // get prev and next images
52 $prevImage = $images[$pos-1];
53 if ($pos < sizeof($images)-1)
54 $nextImage = $images[$pos+1];
57 $imageUrl = dirname($scriptPath)."/".IMAGES_DIR.$shortPath;
59 if ($nextImage === '') {
63 $nextImageUrl = dirname($scriptPath)."/".IMAGES_DIR.dirname($shortPath)."/$nextImage";
64 $nextPageUrl = dirname($_SERVER["REQUEST_URI"])."/$nextImage";
66 if ($prevImage === '') $prevPageUrl = '';
67 else $prevPageUrl = dirname($_SERVER["REQUEST_URI"])."/$prevImage";
69 $directoryUrl = dirname($_SERVER["SCRIPT_NAME"])."/index.php".dirname($shortPath);
71 header('Content-Type: text/html; charset=utf-8');
72 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
76 <style type="text/css">
92 text-decoration: none;
94 #next, #previous, #up {
119 <?php if ($nextImageUrl !== '') { ?>
120 <?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false) { ?>
121 <link rel="prefetch" href="<?php echo $nextImageUrl ?>" />
122 <link rel="prefetch" href="<?php echo $nextPageUrl ?>" />
125 <script type="text/javascript">
126 window.onload = function() {
127 var im = new Image();
128 im.src = '<?php echo $nextImageUrl ?>';
129 var req = new XMLHttpRequest();
130 req.open('GET', '<?php echo $nextPageUrl ?>', false);
140 <a href="<?php echo $imageUrl ?>"><img src="<?php echo $imageUrl ?>" id="theimage" /></a>
143 <a href="<?php echo $directoryUrl ?>" title="Back to directory">^</a>
146 <?php if ($nextPageUrl !== '') { ?>
148 <a href="<?php echo $nextPageUrl ?>" title="Next image">></a>
152 <?php if ($prevPageUrl !== '') { ?>
154 <a href="<?php echo $prevPageUrl ?>" title="Previous image"><</a>