$h) {
$newW = $maxSize;
$newH = $h/($w/$maxSize);
} else {
$newW = $w/($h/$maxSize);
$newH = $maxSize;
}
$newImg = imagecreatetruecolor($newW, $newH);
imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
imagejpeg($newImg, $newImgFile);
imagedestroy($img);
imagedestroy($newImg);
}
return dirname($_SERVER["SCRIPT_NAME"])."/".$newImgFile;
}
function getAlbumPreview($dir)
{
foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') {
if (strtolower(substr($file, -4)) == ".jpg")
return getPreview("$dir/$file", 100);
}
return '';
}
$shortPath = isset($_SERVER["PATH_INFO"]) ? $_SERVER["PATH_INFO"] : "";
if ($shortPath == '/') $shortPath = '';
$scriptUrlPath = substr($_SERVER["SCRIPT_NAME"], 0, -4); // trim .php
$folders = array();
$imageFiles = array();
$otherFiles = array();
$realDir = "images$shortPath";
foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
{
if (is_dir("$realDir/$file"))
{
$folders[] = array( "name" => $file, "link" => "$scriptUrlPath$shortPath/$file", "preview" => getAlbumPreview("$realDir/$file") );
}
else
{
$ext = strtolower(substr($file, -4));
if ($ext == ".jpg")
$imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file", 100), "link" => dirname($scriptUrlPath)."/view/$shortPath/$file" );
else
$otherFiles[] = array( "name" => $file, "link" => dirname($scriptUrlPath)."/$realDir/$file" );
}
}
if (dirname($shortPath) !== '')
$parentLink = $scriptUrlPath.dirname($shortPath);
else
$parentLink = "";
?>