Sp_getthumb.php
<?php
require('sp_config.php');
$source = stripslashes($_GET['source']);
$path = pathinfo($source);
//echo $source;
$hash = md5($source);
switch(strtolower($path["extension"])){
case "jpeg":
case "jpg":
$original=imagecreatefromjpeg($source);
break;
case "gif":
$original=imagecreatefromgif($source);
break;
case "png":
$original=imagecreatefrompng($source);
break;
default:
break;
}
$xratio = $maxthumbwidth/(imagesx($original));
$yratio = $maxthumbheight/(imagesy($original));
if($xratio < $yratio) {
if($gd_version >= 2)
$thumb = imagecreatetruecolor($maxthumbwidth,floor(imagesy($original)$xratio));
else
$thumb = imagecreate($maxthumbwidth,floor(imagesy($original)$xratio));
}
else {
if($gd_version >= 2)
$thumb = imagecreatetruecolor(floor(imagesx($original)$yratio), $maxthumbheight);
else
$thumb = imagecreate(floor(imagesx($original)$yratio), $maxthumbheight);
}
imagecopyresampled($thumb, $original, 0, 0, 0, 0, imagesx($thumb)+1,imagesy($thumb)+1,imagesx($original),imagesy($original));
imagedestroy($original);
//CACHE THE IMAGE IF CACHING HAS BEEN ENABLED
if($cachethumbs)
{
imagejpeg($thumb, $cachefolder . "/" . $hash . ".jpg");
$descriptions = @parse_ini_file('sp_descriptions.ini',true);
$cache_ini = @parse_ini_file($cachefolder . "/cache.ini",true);
$thisfolder = str_replace('sp_getthumb.php','',$_SERVER['PHP_SELF']);
if($modrewrite)
$url = $thisfolder . 'file/' . $source;
else
$url = $thisfolder . 'sp_index.php?file=' . $source;
$cache_ini[$hash]['src'] = $thisfolder . $cachefolder . '/' . $hash . '.jpg';
$cache_ini[$hash]['alt'] = $descriptions[$path['basename']]['desc'];
$cache_ini[$hash]['url'] = $url;
$cache_ini[$hash]['title'] = $descriptions[$path['basename']]['title'];
$cache_ini[$hash]['size'] = filesize($source);
write_ini_file($cachefolder . "/cache.ini", $cache_ini);
}
//RETURN A JPG TO THE BROWSER
imagejpeg($thumb);
imagedestroy($thumb);
function write_ini_file($path, $assoc_array) {
foreach ($assoc_array as $key => $item) {
if (is_array($item)) {
$content .= "\n[$key]\n";
foreach ($item as $key2 => $item2) {
$content .= "$key2 = \"$item2\"\n";
}
} else {
$content .= "$key = \"$item\"\n";
}
}
if (!$handle = fopen($path, 'w')) {
return false;
}
if (!fwrite($handle, $content)) {
return false;
}
fclose($handle);
return true;
}
?>
//
Sp_index.php
<?php
/*
Simple PHP Gallery by Paul Griffin.
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/1.0/
or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
What this means:
You are free:
to copy, distribute, display, and perform the work
to make derivative works
Under the following conditions:
* Attribution. You must give the original author credit.
* Noncommercial. You may not use this work for commercial purposes.
* Share Alike. If you alter, transform, or build upon this work, you may distribute the
resulting work only under a license identical to this one.
* For any reuse or distribution, you must make clear to others the license terms of this work.
* Any of these conditions can be waived if you get permission from the author.
*/
require('sp_helper_functions.php');
require('sp_def_vars.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php getPageTitle(); ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="<?php getCurrentWorkingDirectory();?>/sp_styles.css" media="screen" />
</head>
<body>
<h1><?php getPageTitle(); ?></h1>
<p id="breadcrumb"><?php getBreadCrumbs();?></p>
<?php
//IF A FILE WAS REQUESTED FOR VIEWING, OUTPUT IT
if($display_file != '')
{
?>
<div id="prevnext"><?php getPrevAndNext();?></div><div style="clear:both;"></div>
<div id="image"><?php getFile(); ?></div>
<?php
if(descriptionExists())
{
?>
<p id="desc"><?php getDescription();?></p>
<?php
}
}
//OTHERWISE, A DIRECTORY LISTING REQUEST WAS MADE. DISPLAY THE THUMBNAIL LINKS.
else
{
//IF THIS DIRECTORY HAS A DESCRIPTION, OUTPUT IT
if(getDirDescription() != '')
{
?>
<div id="dirdesc">
<?php echo getDirDescription(); ?>
</div>
<?php
}
//IF THERE ARE SUB-DIRECTORIES, LIST THEM.
if(subDirExist())
{
?>
<div id="directories"> <?php getDirLinks(); ?></div>
<?php
}
?>
<div id="gallery">
<?php
//OUTPUT THUMBNAIL LINKS TO ALL IMAGES IN THIS DIRECTORY
//getThumbnails();
foreach(getImgLinks() as $link)
{
echo $link;
}
?>
</div>
<?php
}
?>
<p id="credit">
Powered by <a href="http://relativelyabsolute.com/spg/">Simple PHP Gallery</a> <?php echo VERSION ?>
</p>
</body>
</html>
//
Sp_resize.php
<?php
require('sp_config.php');
$source = stripslashes($_GET['source']);
$path = pathinfo($source);
$hash = md5(substr($source,2,strlen($source)-2));
switch(strtolower($path["extension"])){
case "jpeg":
case "jpg":
$original=imagecreatefromjpeg($source);
break;
case "gif":
$original=imagecreatefromgif($source);
break;
case "png":
$original=imagecreatefrompng($source);
break;
default:
break;
}
$xratio = $maxwidth/(imagesx($original));
$yratio = $maxheight/(imagesy($original));
if($xratio < 1 || $yratio < 1)
{
if($xratio < $yratio) {
if($gd_version >= 2)
$thumb = imagecreatetruecolor($maxwidth,floor(imagesy($original)$xratio));
else
{
imagejpeg($original);
exit();
}
}
else {
if($gd_version >= 2)
$thumb = imagecreatetruecolor(floor(imagesx($original)$yratio), $maxheight);
else
{
imagejpeg($original);
exit();
}
}
imagecopyresampled($thumb, $original, 0, 0, 0, 0, imagesx($thumb)+1,imagesy($thumb)+1,imagesx($original),imagesy($original));
if($cacheresized)
{
imagejpeg($thumb, $cacheresizedfolder . "/" . $hash . ".jpg");
$resized_cache_ini = @parse_ini_file($cacheresizedfolder . "/resized_cache.ini",true);
$resized_cache_ini[$hash]['size'] = filesize($source);
write_ini_file($cacheresizedfolder . "/resized_cache.ini", $resized_cache_ini);
}
imagejpeg($thumb);
imagedestroy($thumb);
}
else
{
imagejpeg($original);
}
imagedestroy($original);
function write_ini_file($path, $assoc_array) {
foreach ($assoc_array as $key => $item) {
if (is_array($item)) {
$content .= "\n[$key]\n";
foreach ($item as $key2 => $item2) {
$content .= "$key2 = \"$item2\"\n";
}
} else {
$content .= "$key = \"$item\"\n";
}
}
if (!$handle = fopen($path, 'w')) {
return false;
}
if (!fwrite($handle, $content)) {
return false;
}
fclose($handle);
return true;
}
?>