3 $shortPath = $_SERVER["PATH_INFO"];
4 if ($shortPath == '/') $shortPath = '';
5 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
6 if (strpos($shortPath, '..') !== false) die(".. found in url");
8 $scriptPath = $_SERVER["SCRIPT_NAME"];
10 // get all images in an array
13 $files = scandir("images".dirname($shortPath));
14 foreach ($files as $file) {
15 $ext = strtolower(substr($file, -4));
16 if ($ext == ".jpg" or $ext == ".png")
20 // find the image position
21 $pos = array_search(basename($shortPath), $images);
22 if ($pos === false) die("Image not found");
24 // get prev and next images
28 $prevImage = $images[$pos-1];
29 if ($pos < sizeof($images)-1)
30 $nextImage = $images[$pos+1];
33 $imageUrl = dirname($scriptPath)."/images$shortPath";
35 if ($nextImage === '') {
39 $nextImageUrl = dirname($scriptPath)."/images".dirname($shortPath)."/$nextImage";
40 $nextPageUrl = dirname($_SERVER["REQUEST_URI"])."/$nextImage";
42 if ($prevImage === '') $prevPageUrl = '';
43 else $prevPageUrl = dirname($_SERVER["REQUEST_URI"])."/$prevImage";
45 $directoryUrl = dirname($_SERVER["SCRIPT_NAME"])."/index.php".dirname($shortPath);
47 header('Content-Type: text/html; charset=utf-8');
48 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
52 <style type="text/css">
68 text-decoration: none;
70 #next, #previous, #up {
95 <?php if ($nextImageUrl !== '') { ?>
96 <link rel="prefetch" href="<?php echo $nextImageUrl ?>" />
97 <link rel="prefetch" href="<?php echo $nextPageUrl ?>" />
103 <a href="<?php echo $imageUrl ?>"><img src="<?php echo $imageUrl ?>" id="theimage" /></a>
106 <a href="<?php echo $directoryUrl ?>" title="Back to directory">^</a>
109 <?php if ($nextPageUrl !== '') { ?>
111 <a href="<?php echo $nextPageUrl ?>" title="Next image">></a>
115 <?php if ($prevPageUrl !== '') { ?>
117 <a href="<?php echo $prevPageUrl ?>" title="Previous image"><</a>