3 define('IMAGES_DIR', 'images');
5 $shortPath = $_SERVER["PATH_INFO"];
6 if ($shortPath == '/') $shortPath = '';
7 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
8 if (strpos($shortPath, '..') !== false) die(".. found in url");
10 $scriptPath = $_SERVER["SCRIPT_NAME"];
12 // get all images in an array
15 $files = scandir(IMAGES_DIR.dirname($shortPath));
16 foreach ($files as $file) {
17 $ext = strtolower(substr($file, -4));
18 if ($ext == ".jpg" or $ext == ".png")
22 // find the image position
23 $pos = array_search(basename($shortPath), $images);
24 if ($pos === false) die("Image not found");
26 // get prev and next images
30 $prevImage = $images[$pos-1];
31 if ($pos < sizeof($images)-1)
32 $nextImage = $images[$pos+1];
35 $imageUrl = dirname($scriptPath)."/".IMAGES_DIR.$shortPath;
37 if ($nextImage === '') {
41 $nextImageUrl = dirname($scriptPath)."/".IMAGES_DIR.dirname($shortPath)."/$nextImage";
42 $nextPageUrl = dirname($_SERVER["REQUEST_URI"])."/$nextImage";
44 if ($prevImage === '') $prevPageUrl = '';
45 else $prevPageUrl = dirname($_SERVER["REQUEST_URI"])."/$prevImage";
47 $directoryUrl = dirname($_SERVER["SCRIPT_NAME"])."/index.php".dirname($shortPath);
49 header('Content-Type: text/html; charset=utf-8');
50 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
54 <style type="text/css">
70 text-decoration: none;
72 #next, #previous, #up {
97 <?php if ($nextImageUrl !== '') { ?>
98 <link rel="prefetch" href="<?php echo $nextImageUrl ?>" />
99 <link rel="prefetch" href="<?php echo $nextPageUrl ?>" />
105 <a href="<?php echo $imageUrl ?>"><img src="<?php echo $imageUrl ?>" id="theimage" /></a>
108 <a href="<?php echo $directoryUrl ?>" title="Back to directory">^</a>
111 <?php if ($nextPageUrl !== '') { ?>
113 <a href="<?php echo $nextPageUrl ?>" title="Next image">></a>
117 <?php if ($prevPageUrl !== '') { ?>
119 <a href="<?php echo $prevPageUrl ?>" title="Previous image"><</a>