2 header('Content-Type: text/html; charset=utf-8');
3 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
7 <style type="text/css">
10 vertical-align: middle;
14 display: inline-block;
22 vertical-align: middle;
30 function getPreview($imgFile, $maxSize)
32 # example: data/myalbum/100.mypic.jpg
33 $newImgFile = "data/".dirname($imgFile)."/".$maxSize.".".basename($imgFile);
35 if (! is_file($newImgFile))
37 $img = imagecreatefromjpeg($imgFile);
41 # don't do anything if the image is already small
42 if ($w <= $maxSize and $h <= $maxSize) {
47 # create the thumbs directory recursively
48 if (! is_dir(dirname($newImgFile))) mkdir(dirname($newImgFile), 0777, true);
52 $newH = $h/($w/$maxSize);
54 $newW = $w/($h/$maxSize);
58 $newImg = imagecreatetruecolor($newW, $newH);
60 imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
62 imagejpeg($newImg, $newImgFile);
65 imagedestroy($newImg);
68 return dirname($_SERVER["SCRIPT_NAME"])."/".$newImgFile;
71 function getAlbumPreview($dir)
73 foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') {
74 if (strtolower(substr($file, -4)) == ".jpg")
75 return getPreview("$dir/$file", 100);
81 $shortPath = isset($_SERVER["PATH_INFO"]) ? $_SERVER["PATH_INFO"] : "";
82 if ($shortPath == '/') $shortPath = '';
83 $scriptUrlPath = substr($_SERVER["SCRIPT_NAME"], 0, -4); // trim .php
86 $imageFiles = array();
87 $otherFiles = array();
89 $realDir = "images$shortPath";
91 foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
93 if (is_dir("$realDir/$file"))
95 $folders[] = array( "name" => $file, "link" => "$scriptUrlPath$shortPath/$file", "preview" => getAlbumPreview("$realDir/$file") );
99 $ext = strtolower(substr($file, -4));
101 $imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file", 100), "link" => dirname($scriptUrlPath)."/view/$shortPath/$file" );
103 $otherFiles[] = array( "name" => $file, "link" => dirname($scriptUrlPath)."/$realDir/$file" );
107 if (dirname($shortPath) !== '')
108 $parentLink = $scriptUrlPath.dirname($shortPath);
114 <?php if ($parentLink !== '') { ?>
115 <div id="parentfolder"><a href="<?php echo $parentLink ?>">^</a></div>
118 <?php foreach($folders as $folder) { ?>
120 <a href="<?php echo $folder["link"] ?>">
121 <?php if ($folder["preview"] !== "") { ?>
122 <img src="<?php echo $folder["preview"] ?>" />
124 <?php echo $folder["name"] ?>
129 <?php foreach ($imageFiles as $file) { ?>
130 <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>
133 <?php foreach ($otherFiles as $file) { ?>
134 <div class="miscfile"><a href="<?php echo $file["link"] ?>"><?php echo $file["name"] ?></a></div>