Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Need help with Image Gallery Script
Closed Thread
Old 04-22-2006, 04:32 AM   #1 (permalink)
 
Junior Techie

Join Date: Sep 2005

Posts: 91

Haoming

Send a message via AIM to Haoming
Default Need help with Image Gallery Script

Hello, I'm trying to get this image gallery script to work but no luck yet =\
Here's the index.php file but it still won't show anythin =(
If you need anything else that could help solve my problem just ask!

Code:
<?
/*
 * PHOTODIR
 * photodir.php - Main program
 * Version 1.1, 20-Jan-04
 * Copyright 2004 Ross W. Poulton
 * ross@rossp.org
 * http://www.rossp.org/
 * 
 * This file is part of PhotoDir.
 *
 * PhotoDir is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PhotoDir is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PhotoDir; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 */
// Define some basic variables:

/* Directory where photos are stored */
$photo_dir = "/public_html/haoming/pics/pics";

/* Directory for cached thumbnails */
$cache_dir = "/public_html/haoming/pics/pics-cache";

/* URI to where photos are stored */
$photo_url = "/pics";

/* 'Frame' picture - thumbnails will be centred on top of this image */
$frame_pic = "outline.jpg";

/* 'Folder' picture */
$folder_pic = "folder.jpg";

/* 'Parent' picture */
$parent_pic = "folder.jpg";

/* Maximum dimensions for a thumbnail will be $thumb_max * $thumb_max. Thumbs
   are made proportionatly, eg a 200x100 image with thumb_max of 100 will be 
   resized to 100x50. */
$thumb_max = 100;

/* *********************************************** */
/*              END CONFIGURATION                  */
/* *********************************************** */

if ($_GET['photofile']) {
	/* If we're just displaying a photo, send it out to the user. */

	$photo = $photo_dir . "/" . stripslashes($_GET['photofile']);

	if (realpath($photo) != $photo) {
		/* Use realpath to find out if someone has tried spoofing us with
		   ../../../../etc/passwd or similar. */
		exit;
	}
	
	header("Content-type: image/jpeg");
	readfile($photo);
	exit;

} elseif ($_GET['thumbfile']) {

	/* Display a thumbnail. This will be a resized version of the full file, 
	   but superimposed on your outline image. */

	$photo = $photo_dir . "/" . stripslashes($_GET['thumbfile']);
	if (realpath($photo) != $photo) {
		exit;
	}
	header("Content-type: image/jpeg");

	$md5sum = md5("$photo");
	$cache_file = $cache_dir . "/$md5sum";

	if ((!file_exists($cache_file)) ||
	(filemtime($cache_file) < filemtime($photo))) {
	
		$outline_img = imagecreatefromjpeg($photo_dir . "/" . $frame_pic);
		$outline_width = imagesx($outline_img);
		$outline_height = imagesy($outline_img);

		$src_img = imagecreatefromjpeg($photo);

		$size = getimagesize($photo);
		$origw = $size[0];
		$origh = $size[1];

		if ($origw > $origh) {
			$neww = $thumb_max;
			$diff = $origw / $neww;
			$newh = $origh / $diff;
		} else {
			$newh = $thumb_max;
			$diff = $origh / $newh;
			$neww = $origw / $diff;
		}

		$dst_img = imagecreatetruecolor($neww, $newh);

		if (function_exists('imagecopyresampled')) {
			imagecopyresampled($dst_img,$src_img,0,0,0,0,$neww,$newh,
				$origw,$origh);
		} else {
			imagecopyresized($dst_img, $src_img,0,0,0,0,$neww,$newh,$origw,
				$origh);
		}
	
		imagealphablending($outline_img, true);

		/* The following block makes up our co-ordinates for placing the
		thumbnail on the frame.  We always start at least 2 pixels from 
		each edge, and from there the image is centered both horizontally
		and vertically. */

		if ($neww > $newh) {
			$startx = 2;
			$starty = ((100 - $newh) / 2) + 2;
		} else {
			$startx = ((100 - $neww) / 2) + 2;
			$starty = 2;
		}
	
		imagecopy($outline_img, $dst_img, $startx, $starty, 0, 0, $neww, $newh);
		
		imagejpeg($outline_img, $cache_file);
	}

	readfile ($cache_file);

	exit;
}

include "header.html";

/* $dir is the full filesystem directory that we're looking at, eg 
   /var/httpd/photos/Holidays/NewYork2003
   $path is everything AFTER the 'standard' photo directory, eg
   Holidays/NewYork2003 */

if ($_GET['dir'] != "") {
	$dir = $photo_dir . "/" . stripslashes($_GET['dir']);
	$path = $_GET['dir'];
} else {
	$dir = $photo_dir;
	$path = "";
}

if (substr($dir, -1, 1) == "/") {
	/* Remove the trailing slash if there is one */
	$dir = substr($dir, 0, -1);
}

if (substr($path, -1, 1) == "/") {
	/* Remove the trailing slash if there is one */
	$path = substr($path, 0, -1);
}

if ($dir != realpath($dir)) {
	/* Quick check to make sure our path hasn't been 
	   poisened, eg ../../../../etc/passwd or similar. */
	exit;
}

/* Initialise basic variables */
$i = 1;
$first = "y";

if ((is_dir($dir)) && ($dir != "") && ($_GET['image'] == "")) {
	if ($dh = opendir($dir)) {
		echo "<table border=0 width=100%>";

		echo "<tr>";

		while (($file = readdir($dh)) !== false) {
			if (($file != ".") && ($file != "..") &&
			!(($file == $folder_pic) && ($path != "/")) &&
			!(($file == $frame_pic) && ($path != "/"))) {

				if (($first == "y") && ($path != "")) {
					/* If this is the first entry to be displayed on this
					   page, then put in a 'Parent' link to back up a 
					   level. */
					$first = "n";
					$parts = explode("/", $path);

					if (count($parts) == 0) {
						$parent = "";
					} else {
						for ($j=0; $j<count($parts)-1; $j++) {
							$parent .= $parts[$j] . "/";
						}
					}

					echo "<td width=25% align=center valign=top>";
					echo "<a href='$PHP_SELF?dir=$parent'>";
					echo "[img]$photo_url/" . $folder_pic . "[/img]";
					echo "
Parent Directory";
					echo "</a>
";
					echo "</td>\n";
				}

				if (filetype($dir . "/" . $file) == "dir") {
					/* This is a directory, display our folder icon */
					echo "<td width=25% align=center valign=top>";

					echo "<a href='$PHP_SELF?dir=";
					if ($path == "") {
						echo $file;
					} else {
						echo $path . "/" . $file;
					}
					echo "'>";
					echo "<img src='$photo_url/" . $folder_pic;
					echo "'>
$file</a>
";
				
					echo "</td>\n";
					
					$i++;

				} elseif (eregi("jpg", $file)) {
					/* This is an image, display its thumbnail and a link 
					   to the full image. */
					echo "<td width=25% align=center valign=top>";

					echo "<a href='$PHP_SELF?image=$path/$file'>";
					echo "<img src='$PHP_SELF?thumbfile=";
					echo $path . "/" . $file;
					echo "'>
";
					echo eregi_replace(".jpg", "", $file) . "</a>
";
				
					echo "</td>\n";
				
					$i++;

				}


				if ($i == 4) {
					echo "</tr>\n<tr>\n";
					$i = 0;
				}
			}
		}
		closedir($dh);
		echo "</tr></table>";
	} else {
		echo "That directory can't be opened! :(
";
		echo "Maybe try checking permissions.
";
	}
} else {
	/* Display large photo and information */

	echo "<h2 align=center>";
	echo eregi_replace(".jpg", "", basename($photo_dir . $_GET['image']));
	echo "</h2>";

	echo "<p align=center>";

	echo "[img]$PHP_SELF?photofile=" . stripslashes($_GET[[/img]";
	echo "
";
	
	$size = getimagesize($photo_dir . "/" . $_GET['image']);
	$origw = $size[0];
	$origh = $size[1];

	echo "Photo Size: $origw x $origh pixels
";
	
	echo "Filesize: ";
	echo format_file_size(filesize($photo_dir . "/" . $_GET['image']));
	echo "
";

	echo "Last Modified: ";
	echo date("d-m-y", filemtime($photo_dir . "/" . $_GET['image']));
	echo "
";

	$parts = explode("/", stripslashes($_GET['image']));
	if (count($parts) == 0) {
		$parent = "";
	} else {
		for ($j=0; $j<count($parts)-1; $j++) {
			$parent .= $parts[$j] . "/";
		}
		$parent = substr($parent, 0, -1);
	}
	echo "
";
	echo "Back";
	echo "</p>";
}

include "footer.html";

function format_file_size($size) {
	if ($size <= 1024) {
		return $size . "Mb";
	} elseif (($size > 1024) && ($size <= 1024000)) {
		$size = $size / 1024;
		$size = round($size, 2);
		return $size . "Kb";
	} elseif (($size > 1024000) && ($size <= 1024000000)) {
		$size = $size / 1024000;
		$size = round($size, 2);
		return $size . "Mb";
	} else {
		$size = $size / 1024000000;
		$size = round($size, 2);
		return $size . "Gb";
	}
}

?>
Thanks
Haoming is offline  
Old 04-24-2006, 02:39 AM   #2 (permalink)
 
Junior Techie

Join Date: Oct 2005

Posts: 75

darkninja

Default

As I can see, a guy called Ross something wrote it and your trying to install it somewhere and run it, right?

Well what exactly happens when you try install/run this script? I had a quick glance over the coding and it looks alright (I lie, I just looked at it and it was neat and tidy). Like what error messages do you get or what is displayed when you try to run it? More specific information would be helpful
__________________
<a href="http://www.flashyflashy.net" target="_blank">flashyflashy.net</a>
darkninja is offline  
Old 04-25-2006, 09:22 PM   #3 (permalink)
 
Junior Techie

Join Date: Sep 2005

Posts: 91

Haoming

Send a message via AIM to Haoming
Default

well this is for a photo gallery

there's no error page

just a blank page with the header

for some reason it just won't display anything after the header

here's a few more files if you wanna take a look at em

Header.html :

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>

<title>Haoming's Picture Gallery</title>

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="Haoming" />
<meta name="description" content="blank" />
<meta name="keywords" content="haoming" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="MSSmartTagsPreventParsing" content="true" />

<style type='text/css'><!--

body {
	background-color: #eee;
	color: #000;
}

h1 {
	font-family:Tahoma, sans-serif;
}


a {
	text-decoration: none;
	color:#00f;
}


a:visited {
	text-decoration:none;
	color:#00f;
}

a:hover {
	text-decoration: none;
	color:#f00;
}

td {
	font-family: sans-serif;
	font-size: 12px;
}
body {
	font-family: sans-serif;
	font-size: 12px;
}

img {
	border:0;
}

img.photo {
	border: solid 3px #999;
}

.footer {
	font-size:x-small;
	text-align:center;
}

.arrow_l {
position:absolute;
top:58px;
left:50px;
border:1px solid #999;
}

.arrow_l:hover {
border:1px solid #800000;
}

.arrow_r {
position:absolute;
top:58px;
right:50px;
border:1px solid #999;
}

.arrow_r:hover {
border:1px solid #800000;
}

-->
</style>

</head>

<body>

<h1>Haoming's Picture Gallery</h1>

Footer.html :

Code:
<hr />
<div class="footer">Powered by PhotoDir</div>
</body></html>

Haoming is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On