3 define('THUMB_SIZE', 100);
4 define('DATA_DIR', 'data');
5 define('IMAGES_DIR', 'images');
6 define('USE_VIEWER', true);
8 function getPreview($imgFile, $maxSize = THUMB_SIZE)
10 # example: data/myalbum/100.mypic.jpg
11 $newImgFile = DATA_DIR."/".dirname($imgFile)."/".$maxSize.".".basename($imgFile);
13 if (! is_file($newImgFile))
15 $ext = strtolower(substr($imgFile, -4));
17 $img = imagecreatefromjpeg($imgFile);
19 $img = imagecreatefrompng($imgFile);
23 # don't do anything if the image is already small
24 if ($w <= $maxSize and $h <= $maxSize) {
29 # create the thumbs directory recursively
30 if (! is_dir(dirname($newImgFile))) mkdir(dirname($newImgFile), 0777, true);
34 $newH = $h/($w/$maxSize);
36 $newW = $w/($h/$maxSize);
40 $newImg = imagecreatetruecolor($newW, $newH);
42 imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
45 imagejpeg($newImg, $newImgFile);
47 imagepng($newImg, $newImgFile);
50 imagedestroy($newImg);
53 return dirname($_SERVER["SCRIPT_NAME"])."/".$newImgFile;
56 function getAlbumPreview($dir)
58 foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') {
59 $ext = strtolower(substr($file, -4));
60 if ($ext == ".jpg" or $ext == ".png")
61 return getPreview("$dir/$file");
67 $scriptUrlPath = $_SERVER["SCRIPT_NAME"];
69 // if url == http://localhost/photos/index/toto/titi, path_info == /toto/titi
70 // if url == http://localhost/photos/index, path_info is not set
71 // if url == http://localhost/photos/, path_info is not set
72 // if path_info is not set, we are at top level, so we redirect to /photos/index/
73 if (! isset($_SERVER["PATH_INFO"])) {
74 header("Location: $scriptUrlPath/");
78 $shortPath = $_SERVER["PATH_INFO"];
79 if ($shortPath == '/') $shortPath = '';
80 // extra security check to avoid /photos/index/../.. like urls, maybe useless but..
81 if (strpos($shortPath, '..') !== false) die(".. found in url");
84 $imageFiles = array();
85 $otherFiles = array();
87 $realDir = IMAGES_DIR.$shortPath;
89 foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
91 if (is_dir("$realDir/$file"))
93 $folders[] = array( "name" => $file, "link" => "$scriptUrlPath$shortPath/$file", "preview" => getAlbumPreview("$realDir/$file") );
97 $ext = strtolower(substr($file, -4));
98 if ($ext == ".jpg" or $ext == ".png") {
100 $link = dirname($scriptUrlPath)."/view.php$shortPath/$file";
102 $link = dirname($scriptUrlPath)."/$realDir/$file";
104 $imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file"), "link" => $link );
107 $otherFiles[] = array( "name" => $file, "link" => dirname($scriptUrlPath)."/$realDir/$file" );
112 if (dirname($shortPath) !== '')
113 $parentLink = $scriptUrlPath.dirname($shortPath);
119 ///// template starts here /////
120 header('Content-Type: text/html; charset=utf-8');
121 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
125 <style type="text/css">
133 text-decoration: none;
136 display: inline-block;
139 width: <?php echo THUMB_SIZE ?>px;
140 height: <?php echo THUMB_SIZE ?>px;
143 vertical-align: middle;
146 height: <?php echo THUMB_SIZE ?>px;
148 vertical-align: middle;
161 <?php if ($parentLink !== '') { ?>
162 <div id="parentfolder"><a href="<?php echo $parentLink ?>">^</a></div>
165 <?php foreach($folders as $folder) { ?>
167 <?php if ($folder["preview"] === "") { ?>
168 <a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a>
170 <div class="square"><div class="image"><a href="<?php echo $folder["link"] ?>"><img src="<?php echo $folder["preview"] ?>" /></a></div></div>
171 <div class="square"><div class="foldername"><a href="<?php echo $folder["link"] ?>"><?php echo $folder["name"] ?></a></div></div>
176 <?php foreach ($imageFiles as $file) { ?>
177 <div class="square"><div class="image"><a href="<?php echo $file["link"] ?>"><img src="<?php echo $file["url"] ?>" alt="<?php echo $file["name"] ?>" /></a></div></div>
180 <?php foreach ($otherFiles as $file) { ?>
181 <div class="miscfile"><a href="<?php echo $file["link"] ?>"><?php echo $file["name"] ?></a></div>