HEX
Server: Apache
System: Linux www3.pit.tblive.com 5.14.0-687.38.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Aug 12 17:19:12 EDT 2026 x86_64
User: awaldron (1020)
PHP: 8.1.34
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //home/awaldron/public_html/aw/photos/photodex.php
<?php
session_start();

/************************************************************************************************
	Script Variables : You can customize these constants...
************************************************************************************************/

	define("PAGE_TITLE","photos.alanwaldron.com");
	define("MAX_THUMB_WIDTH",100);
	define("MAX_THUMB_HEIGHT",100);
	define("MAX_PHOTO_WIDTH",800);
	define("MAX_PHOTO_HEIGHT",800);
	
	
	// Use these variables if you have access to a MySQL Database
	define("MYSQL",1);  		         			// 1 = Yes, you have a database;  0 = No, you don't have a database
	define("MYSQL_HOST","localhost");      			// MySQL Host Name (usually 'localhost')
	define("MYSQL_USER","awaldron");       			// MySQL Username (usually 'root')
	define("MYSQL_PASS","EcEgElm@lt@");       			// MySQL Password
	define("MYSQL_DATABASE","awaldron_photos");		// MySQL Database name
	define("MYSQL_PHOTO_TABLE","photos");    		// Table Name to store photo information
	define("MYSQL_COMMENT_TABLE","comments");    	// Table Name to store photo comments
	define("ADMIN_USER","admin");					// Admin Username to login to photo system 	
	define("ADMIN_PASS","mmt2mmw");					// Admin Password to login to photo system 	


/************************************************************************************************
	No Need to edit anything below here (unless you really really want to...)
************************************************************************************************/














/************************************************************************************************
	Purpose: class to handle image resize; can output to file or directly to browser
	Author:	Yuriy Horobey, yuriy@horobey.com
	Property: Horobey Freelance & Telecommuting
	URL: http://horobey.com
	Date: 12.04.2003
************************************************************************************************/

	$ERR["UNABLE_TO_OUTPUT"]		= "Unable to output: ";
	$ERR["FILE_DOESNOT_EXSIT"]		= "This file does not exist: ";
	$ERR["FUNCTION_DOESNOT_EXIST"]	= "This function does not exist: ";
	$ERR["GD2_NOT_CREATED"]			=	"GD2 is installed, function ImageCreateTruecolor() exists, but image is not created";
	$ERR["IMG_NOT_CREATED"]			=	"Image is not created ImageCreate(). {GD2 suppor is OFF}";
	$ERR["GD2_UNAVALABLE"]			=	"You specified to use GD2, but not all GD2 functions are present.";
	$ERR["GD2_NOT_RESIZED"]			=	"GD2 is installed, function ImageCopyResampled() exists, but image is not resized";
	$ERR["IMG_NOT_RESIZED"]			=	"Image was not resized. {GD2 suppor is OFF}";
	$ERR["UNKNOWN_OUTPUT_FORMAT"]	=	"This image format cannot bu output: ";
	$ERR["NO_IMAGE_FOR_OUTPUT"]		=	"Image you are trying to output does not exist. ";
	$ERR["IMG_NOT_SUPPORTED"]		=	"Can not create image. Sorry, this image type is not supported yet.";

	//this class works with image
	class hft_image {
		var $image_original;
		var $file_original;
		var $image_original_width;
		var $image_original_height;
		var $image_original_type_code;
		var $image_original_type_abbr;
		var $image_original_html_sizes;

		var $image_resized;
		var $file_resized;
		var $image_resized_width;
		var $image_resized_height;
		var $image_resized_type_code;
		var $image_resized_type_abbr;
		var $image_resized_html_sizes;

		//some settings
		var $jpeg_quality;
		var $use_gd2;

		
		function hft_image($file_original){
			//constructor of the class
			//it takes given file and creates image out of it
			global $ERR;
			$this->clear(); // clear all.

			if(file_exists($file_original))	{
				$this->file_original = $file_original;
				$this->image_original = $this->imagecreatefromfile($file_original);
				if(!$this->image_original){
					$this->error($ERR["IMAGE_NOT_CREATED_FROM_FILE"]." file=$file_original"); 
					return false;
				}


			} else {
				$this->error($ERR["FILE_DOESNOT_EXSIT"]." file=$file_original");
			}
		}

		function clear() {
			// clear all the class member varaibles

				$this->image_original			=	0;
				$this->file_original			=	"";
				$this->image_original_width		=	0;
				$this->image_original_height	=	0;
				$this->image_original_type_code	=	0;
				$this->image_original_type_abbr	=	"";
				$this->image_original_html_sizes=	"";

				$this->image_resized			=	0;
				$this->file_resized				=	"";
				$this->image_resized_width		=	0;
				$this->image_resized_height		=	0;
				$this->image_resized_type_code	=	-1;
				$this->image_resized_type_abbr	=	"";
				$this->image_resized_html_sizes	=	"";

				$this->set_parameters();

		}

		function set_parameters($jpeg_quality="85", $use_gd2=true) {

			$this->jpeg_quality=$jpeg_quality;
			$this->use_gd2=$use_gd2;
		}

		function error($msg){
			//error messages and debug info:
			// here you can implement your own error handling
			echo("<hr color='red'><font color='red'><b>$msg</b></font><br> file=<b>".__FILE__."</b><hr color='red'>");
		}
	

		function imagecreatefromfile($img_file){
			global $ERR;
			$img=0;
			$img_sz =  getimagesize( $img_file ); 	## returns array with some properties like dimensions and type;
			####### Now create original image from uploaded file. Be carefull! GIF is often not supported, as far as I remember from GD 1.6
			switch( $img_sz[2] ){
				case 1:
					$img = $this->_imagecheckandcreate("ImageCreateFromGif", $img_file);
					$img_type = "GIF";
				break;
				case 2: 
					$img = $this->_imagecheckandcreate("ImageCreateFromJpeg", $img_file);
					$img_type = "JPG";
				break;
				case 3: 
					$img = $this->_imagecheckandcreate("ImageCreateFromPng", $img_file);
					$img_type = "PNG";
				break;
				// would be nice if this function will be finally supported
				case 4: 
					$img = $this->_imagecheckandcreate("ImageCreateFromSwf", $img_file);
					$img_type = "SWF";
				break;
				default:
					$img = 0;
					$img_type = "UNKNOWN";
					$this->error($ERR["IMG_NOT_SUPPORTED"]." $img_file");
					break;
				
			}//case
		
			if($img){
				$this->image_original_width=$img_sz[0];
				$this->image_original_height=$img_sz[1];
				$this->image_original_type_code=$img_sz[2];
				$this->image_original_type_abbr=$img_type;
				$this->image_original_html_sizes=$img_sz[3];

			}else {
				$this->clear();

			}

			return $img;		
		}


		function _imagecheckandcreate($function, $img_file) {
			//inner function used from imagecreatefromfile(). 
			//Checks if the function exists and returns
			//created image or false
			global $ERR;
			if(function_exists($function)) {
				$img = $function($img_file); 
			}else{
				$img = false;
				$this->error($ERR["FUNCTION_DOESNOT_EXIST"]." ".$function);
			}

			return $img;
			
		}

		function resize($desired_width, $desired_height, $mode="-"){
			//this is core function--it resizes created image
			//if any of parameters == "*" then no resizing on this parameter
			//>> mode = "+" then image is resized to cover the region specified by desired_width, _height
			//>> mode = "-" then image is resized to fit into the region specified by desired_width, _height
			// width-to-height ratio is all the time the same
			//>>mode=0 then image will be exactly resized to $desired_width _height.
			//geometrical distortion can occur in this case.
			// say u have picture 400x300 and there is circle on the picture
			//now u resized in mode=0 to 800x300 -- circle shape will be distorted and will look like ellipse.
			//GD2 provides much better quality but is not everywhere installed
			global $ERR;
			if($desired_width == "*" && $desired_height == "*"){
				$this->image_resized = $this->image_original;
				Return true;
			}
			switch($mode) {
				case "-":
				case '+':
					//multipliers
					if($desired_width != "*") $mult_x = $desired_width / $this->image_original_width;		
					if($desired_height != "*") $mult_y = $desired_height / $this->image_original_height;				
					$ratio = $this->image_original_width / $this->image_original_height;

					if($desired_width == "*"){
						$new_height = $desired_height;
						$new_width = $ratio * $desired_height;
					}elseif($desired_height == "*"){
						$new_height = $desired_width / $ratio;
						$new_width =  $desired_width;

					}else{
						if($mode=="-"){
								if( $this->image_original_height * $mult_x < $desired_height ){
								//image must be smaller than given $desired_ region
								//test which multiplier gives us best result

									//$mult_x does the job
									$new_width = $desired_width;
									$new_height = $this->image_original_height * $mult_x;
								}else{
									//$mult_y does the job
									$new_width = $this->image_original_width * $mult_y;
									$new_height = $desired_height;
								}

						}else{
							//mode == "+"
							// cover the region
							//image must be bigger than given $desired_ region
							//test which multiplier gives us best result
							if( $this->image_original_height * $mult_x > $desired_height ){
								//$mult_x does the job
								$new_width = $desired_width;
								$new_height = $this->image_original_height * $mult_x;
							}else{
								//$mult_y does the job
								$new_width = $this->image_original_width * $mult_y;
								$new_height = $desired_height;
							}

						}
					}
				break;

				case '0':
					//fit the region exactly.
					if($desired_width == "*") $desired_width = $this->image_original_width;		
					if($desired_height == "*") $desired_height = $this->image_original_height;	
					$new_width = $desired_width;
					$new_height = $desired_height;
					
				break;
				default: 
					$this->error($ERR["UNKNOWN_RESIZE_MODE"]."  $mode");
				break;
			}
			
			// OK here we have $new_width _height
			//create destination image checking for GD2 functions:
			if( $this->use_gd2 ){
				if( function_exists("imagecreatetruecolor")){
				
					$this->image_resized = imagecreatetruecolor($new_width, $new_height) or $this->error($ERR["GD2_NOT_CREATED"]);
				}else {
					$this->error($ERR["GD2_UNAVALABLE"]." ImageCreateTruecolor()");
				}
			} else {
			
			
				$this->image_resized = imagecreate($new_width, $new_height) or $this->error($ERR["IMG_NOT_CREATED"]);
			}

			//Resize
			if( $this->use_gd2 ){

				if( function_exists("imagecopyresampled")){
					$res = imagecopyresampled($this->image_resized, 
											  $this->image_original, 
											  0, 0,  //dest coord
											  0, 0,			//source coord
											  $new_width, $new_height, //dest sizes
											  $this->image_original_width, $this->image_original_height // src sizes
											) or $this->error($ERR["GD2_NOT_RESIZED"]); 

				}else {
					$this->error($ERR["GD2_UNAVALABLE"]." ImageCopyResampled()");
				}
			} else {
			
				$res = imagecopyresized($this->image_resized, 
										  $this->image_original, 
										  0, 0,  //dest coord
										  0, 0,			//source coord
										  $new_width, $new_height, //dest sizes
										  $this->image_original_width, $this->image_original_height // src sizes
										) or $this->error($ERR["IMG_NOT_RESIZED"]); 
			}

		}
		
		function output_original($destination_file, $image_type="JPG") { 
            //outputs original image 
            //if destination file is empty  image will be output to browser 
            // right now $image_type can be JPG or PNG     
            return _output_image($destination_file, $image_type, $this->image_original); 
        } 
        
		function output_resized($destination_file, $image_type="JPG") { 
            //if destination file is empty  image will be output to browser 
            // right now $image_type can be JPG or PNG    
            $res = $this->_output_image($destination_file, $image_type, $this->image_resized); 
            if(trim($destination_file)){ 
                $sz=getimagesize($destination_file); 
                $this->file_resized = $destination_file; 
                $this->image_resized_width = $sz[0]; 
                $this->image_resized_height = $sz[1]; 
                $this->image_resized_type_code=$sz[2]; 
                $this->image_resized_html_sizes=$sz[3]; 
                    //only jpeg and png are really supported, but I'd like to think of future 
                switch($this->image_resized_html_sizes){ 
                    case 0: 
                        $this->image_resized_type_abbr = "GIF"; 
                    break; 
                    case 1: 
                        $this->image_resized_type_abbr = "JPG"; 
                    break; 
                    case 2: 
                        $this->image_resized_type_abbr = "PNG"; 
                    break; 
                    case 3: 
                        $this->image_resized_type_abbr = "SWF"; 
                    break; 
                    default: 
                        $this->image_resized_type_abbr = "UNKNOWN"; 
                    break; 
                } 
                 
            } 
            return $res; 
        } 

        function _output_image($destination_file, $image_type, $image){ 
            //if destination file is empty  image will be output to browser 
            // right now $image_type can be JPEG or PNG     
            global $ERR; 
            $destination_file = trim($destination_file); 
            $res = false; 
            if($image){ 
                switch($image_type) { 
                    case 'JPEG': 
                    case 'JPG': 
                     
                        $res = ImageJpeg($image, $destination_file, $this->jpeg_quality); 
                    break; 
                    case 'PNG': 
                        $res = Imagepng($image, $destination_file); 
                    break; 
                    default: 
                        $this->error($ERR["UNKNOWN_OUTPUT_FORMAT"]." $image_type"); 
                    break; 
             
                } 
            }else{ 
                $this->error($ERR["NO_IMAGE_FOR_OUTPUT"]); 
            } 
            if(!$res) $this->error($ERR["UNABLE_TO_OUTPUT"]." $destination_file"); 
            return $res; 
        } 
}

//***********************************************************************************************************************//
// END OF CLASS *********************************************************************************************************//
// BEGIN MAIN BODY OF PROGRAM *******************************************************************************************//
//***********************************************************************************************************************//

// Process Login
if (isset($_POST["user"]) && isset($_POST["pass"])) {	
	$login_ok = false;
	$login_att = false;
	if (isset($_POST["user"]) && isset($_POST["pass"])) {
		$login_att = true;		
		if (($_POST["user"] == ADMIN_USER) && ($_POST["pass"] == ADMIN_PASS)) {
			$login_ok = true; 
			$_SESSION["user"] = "admin";
		}
	} 		
	if ($login_att && $login_ok) {
		if (isset($_POST[refer])) header("Location: ".$_POST["refer"]);
		else header("Location: index.php");
	} else if ($login_att && !$login_ok) {
		header("Location: index.php?login=9");
	}
}

// Process Logout
if (isset($_GET[logout])) {
	session_unset();
	session_destroy();
	header("Location: index.php");
}

// Process Edit Caption
if (isset($_POST[action]) && ($_POST[action] == "editcap")) {
	dbconnect();
	quickUPDATE("UPDATE ".MYSQL_PHOTO_TABLE." SET caption='".$_POST[caption]."' WHERE filepath='".$_GET["photo"]."'");
}
?>

<html>
<head>
<title><?=PAGE_TITLE?></title>

<style type="text/css">
body { font-size:12px; font-family:Arial; margin:20px; line-height:20px; }

img.folder  { margin-bottom: -3px; }
img.photo-on { border-color:#000; filter:alpha(opacity=50); -moz-opacity: 0.5; opacity: 0.5; }

a			{ color:#0000FF; font-weight:bold; }
a:link		{ color:#0000FF; font-weight:bold; }
a:active	{ color:#0000FF; font-weight:bold; }
a:visited	{ color:#663399; font-weight:bold; }
a:hover		{ color:#DD0000; font-weight:bold; }

a		  img { color:#000000; font-weight:bold; border-width:1px; margin:1px; }
a:link	  img { color:#000000; font-weight:bold; border-width:1px; margin:1px; }
a:active  img { color:#000000; font-weight:bold; border-width:1px; margin:1px; }
a:visited img { color:#663399; filter:alpha(opacity=60); -moz-opacity: 0.6; opacity: 0.6; border-width:1px; margin:1px; }
a:hover	  img { color:#DD0000; filter:alpha(opacity=100); -moz-opacity: 1.0; opacity: 1.0; border-width:2px; margin:0px; }

.title   { background:#DFDFDF; padding:6px; font-size:18px; font-weight:bold; }
.title-r   { font-size:12px; font-weight:bold; float:right; }
.heading { background:#EEEEEE; padding:6px; border-bottom:1px solid #CCCCCC; }
.folder-list { float:left; margin:0px 10px 0px 5px;  overflow:auto; margin-bottom:50px; }
.thumb-area  { overflow:auto; margin-bottom:50px; }
.thumbnail   { height:150px; float:left; margin:0px 5px 5px 5px; padding:4px; text-align:center; font:10px Arial; }
.curr-dir    { font-size:14px; }
.photo-info    { font-size:14px; float:right; text-align:right; }

.photo-thumbs { float:left; width:120px; text-align:center; margin-right:10px; margin-bottom:50px; }
.photo-main   { float:left; border:1px; text-align:center; }
.photo-main img { border:1px solid #000000; }

.main-body { width:100%; overflow:auto; }
.footer { width:100%; text-align:center; margin-top:50px; }
</style>

<script>
<!--
function edit_caption(fp,cap) {
	var newHTML = '<form name="editcap" action="" method="post">';
	    newHTML += '<input type="hidden" name="action" value="editcap">';
	    newHTML += '<input type="hidden" name="filepath" value="'+fp+'">';
	    newHTML += '<input type="text" name="caption" value="'+cap.replace(/\%/g,'&quot;')+'" size="100"> <input type="submit" name="editcap" value="Submit">';
	    newHTML += '</form>';
	var caption = document.getElementById('caption');
	caption.innerHTML = newHTML;
	document.editcap.caption.focus();
}
-->
</script>
</head>

<body>

<?php
function dbconnect() {
	$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS);
    if (!$db) { return error("Could not connect to DB.<br>".mysql_error()); }
    else { mysql_select_db(MYSQL_DATABASE); return 1; }
}
function is_logged() {
	if ($_SESSION["user"] == "admin") return true;
    else return false;
}
function quickROW($sql) {
	$res = mysql_query($sql);
	if (mysql_num_rows($res) > 0) { $row = mysql_fetch_array($res); return $row; } 
	else return FALSE;
}
function quickSQL($sql) {
	$res = mysql_query($sql);
	if (mysql_num_rows($res) == 1) { $row = mysql_fetch_row($res); return $row[0]; } 
	else return FALSE;
	//else { echo "\n<P>".$sql."\n<P>".mysql_error(); return FALSE; }
}
function quickUPDATE($sql) {
	if (mysql_query($sql) > 0) return TRUE;
	else return FALSE;
}


if (MYSQL) dbconnect();

if (isset($_GET["login"])) {

	echo "<div class=\"title\">\n";
	echo "<div class=\"title-r\">";
	if (MYSQL) {
		if (is_logged()) echo "<a href=\"index.php?logout=1\">Logout</a> | ";
		else echo "<a href=\"index.php?login=1\">Login</a> | ";
	}
	echo "<a href=\"http://www.alanwaldron.com\">AlanWaldron.com</a> | <a href=\"http://blog.alanwaldron.com\">Blog</a></div>\n";
	print PAGE_TITLE."</div>";
	echo "<div class=\"heading\">Login</div><br />\n";
		
	if (!MYSQL) {		
		echo "<br><br><br><center><b style=\"color:#CC0000;\">You must enable MySQL access to login.</b></center><br><br><br><br><br><br>";
		
	} else {	
		$msg = "";
		if ($_GET["login"]==9) $msg = "ERROR: Invalid username/password.";			
		echo "<center><table border=0 cellspacing=4 >\n";
		echo "<tr><td align=\"center\" colspan=2>".($msg!=""?$msg:"")."<br>&nbsp;</td></tr>\n";
		echo "<form action=\"index.php\" method=\"post\" name=\"loginform\">\n";
		//echo "<input type=\"hidden\" name=\"refer\" value=\"".(isset($_POST["refer"])?$_POST["refer"]:self())."\">\n";
		echo "<tr><td><b>Username:</b></td><td><input type=\"text\" name=\"user\" style=\"width:150px\" maxlength=32></td></tr>\n";
		echo "<tr><td><b>Password:</b></td><td><input type=\"password\" name=\"pass\" style=\"width:150px\" maxlength=32></td></tr>\n";
		echo "<tr><td colspan=2 align=center><input type=\"submit\" name=\"login\" value=\"Login\"></td></tr>\n";
		echo "</form></table></center>\n";
	}

	
} else if (isset($_GET["photo"])) {
	
	if (MYSQL) {
		// Update View Count
		if (quickSQL("SELECT count(filepath) FROM ".MYSQL_PHOTO_TABLE." WHERE filepath='".$_GET["photo"]."'")) {
			quickUPDATE("UPDATE ".MYSQL_PHOTO_TABLE." SET viewcount=viewcount+1 WHERE filepath='".$_GET["photo"]."'");
		} else quickUPDATE("INSERT INTO ".MYSQL_PHOTO_TABLE." (filepath,viewcount) VALUES ('".$_GET["photo"]."',1)");
		
		$row = quickROW("SELECT * FROM ".MYSQL_PHOTO_TABLE." WHERE filepath='".$_GET["photo"]."'");
		$views = $row[viewcount];
		$caption = $row[caption];
		$jcaption = str_replace("\"","%",str_replace("'","\'",$caption));
	}
		
	
	# Build $path variable from photo path
	$path = substr($_GET["photo"],0,strrpos($_GET["photo"],"/"));
	
	# Initialise list arrays, directories and files separately and array counters for them
	$d_arr = array(); $d = 0;
	$f_arr = array(); $f = 0;
	
	# Open possibly available directory
	if (is_dir($path)) {
		if($handle = opendir($path)) {
			while (false !== ($file = readdir($handle))) {
				# Make sure we don't push parental directories or dotfiles (unix) into the arrays
				if ($file != "cgi-bin" && $file != "." && $file != ".." && $file[0] != "." && !strstr($file,"zyx_")) {
					if (is_dir($path . "/" . $file)) $d_arr[$d++] = $file;
					else $f_arr[$f++] = $file;
				}
			}
		}
	}
	
	# Wrap things up if we're in a directory
	if (is_dir($handle)) closedir($handle);
	
	# Sort and reset the arrays
	sort($f_arr); reset($f_arr);
	
	echo "<div class=\"title\">\n";
	echo "<div class=\"title-r\">";
	if (MYSQL) {
		if (is_logged()) echo "<a href=\"index.php?logout=1\">Logout</a> | ";
		else echo "<a href=\"index.php?login=1\">Login</a> | ";
	}
	echo "<a href=\"http://www.alanwaldron.com\">AlanWaldron.com</a> | <a href=\"http://blog.alanwaldron.com\">Blog</a></div>\n";
	print PAGE_TITLE."</div>";
	echo "<div class=\"heading\">";
	if (MYSQL) {
		echo "<div class=\"photo-info\">Views: ".$views."<b></b></div>\n";
	}
	echo "<div class=\"curr-dir\">Viewing Photo: <b>" . $_GET["photo"] . "</b></div>";
	$d_prev = substr($path,0,(strrpos(dirname($path."/."),"/")));
	echo "<img src=\"folderback.gif\" border=0 class=\"folder\"> &nbsp;<a href=\"?path=".$path."\">Back to Thumbnails</a>\n";
	echo "</div><br />\n";
	
	echo "<div class=\"main-body\">\n";
	echo "<div class=\"photo-thumbs\">\n";
	$thumb_pos = array_search(substr($_GET["photo"],strrpos($_GET["photo"],"/")+1),$f_arr);
	$thumb_ctr = count($f_arr);
	if ($thumb_pos < 2) { $start = 0; $end = 4; }
	else if ($thumb_pos+2 >= $thumb_ctr) { $start = $thumb_ctr - 5; $end = $thumb_ctr - 1; }
	else { $start = $thumb_pos-2; $end = $thumb_pos+2; }
	if ($end > ($thumb_ctr-1)) $end = $thumb_ctr-1;
	if ($start < 0) $start = 0;
	for ($i=$start; $i <= $end; $i++) {
		if (MYSQL) {
			$thiscap = quickSQL("SELECT caption FROM ".MYSQL_PHOTO_TABLE." WHERE filepath='".$path."/".$f_arr[$i]."'");
			$thiscap = str_replace("\"","&#34;",$thiscap);
		}
		echo "<p><a href=\"?photo=".$path."/".$f_arr[$i]."\"><img src=\"".$path."/zyx_".$f_arr[$i]."\" alt=\"".$thiscap."\" title=\"".$thiscap."\"></a></p>\n";
	}
	echo "</div>\n";
	
	echo "<div class=\"photo-main\">\n";
	echo "<p><img src=\"".$path."/".$f_arr[$thumb_pos]."\"></p>\n";
	if (MYSQL) {
		echo "<div id=\"caption\"><b>".$caption."</span></b>"; 
		if (is_logged()) echo " ( <a href=\"javascript:edit_caption('".$_GET["photo"]."','".$jcaption."');\">".($caption?"edit":"Add Caption to Photo")."</a> )";
		echo "</div>\n";
	}
	echo "</div>\n";
	echo "</div>\n";

} else {

	# Do we have a path? if not, it's the current directory
	$path = $_GET["path"];
	if( !isset( $path ) || $path == "" )  $path = ".";
	
	echo "<div class=\"title\">\n";
	echo "<div class=\"title-r\">";
	if (MYSQL) {
		if (is_logged()) echo "<a href=\"index.php?logout=1\">Logout</a> | ";
		else echo "<a href=\"index.php?login=1\">Login</a> | ";
	}
	echo "<a href=\"http://www.alanwaldron.com\">AlanWaldron.com</a> | <a href=\"http://blog.alanwaldron.com\">Blog</a></div>\n";
	print PAGE_TITLE."</div>";
	echo "<div class=\"heading\">";
	if ($path != ".") {
		echo "<div class=\"curr-dir\">Current Directory: <b>Photo_Root" . substr($path,1) . "</b></div>";
		$d_prev = substr($path,0,(strrpos(dirname($path."/."),"/")));
		echo "<img src=\"folderup.gif\" border=0 class=\"folder\"> &nbsp;<a href=\"?path=".$d_prev."\">Up One Level</a>\n";
	} else {
		echo "<div class=\"curr-dir\">Current Directory: <b>Photo_Root</b></div>";
	}
	echo "</div><br /><br />\n";
	echo "<div class=\"main-body\">\n";
	
	# Initialise list arrays, directories and files separately and array counters for them
	$d_arr = array(); $d = 0;
	$f_arr = array(); $f = 0;
	
	# Open possibly available directory
	if (is_dir($path)) {
		if($handle = opendir($path)) {
			while (false !== ($file = readdir($handle))) {
				# Make sure we don't push parental directories or dotfiles (unix) into the arrays
				if ($file != "cgi-bin" && $file != "." && $file != ".." && $file[0] != ".") {
					if (is_dir($path . "/" . $file)) $d_arr[$d++] = $file;
					else $f_arr[$f++] = $file;
				}
			}
		}
	}
	
	# Wrap things up if we're in a directory
	if (is_dir($handle)) closedir($handle);
	
	# Sort and reset the arrays
	sort($d_arr); reset($d_arr);
	sort($f_arr); reset($f_arr);
	

	
	# Print the directory list
	echo "<div class=\"folder-list\">\n";
	for( $i=0; $i < count( $d_arr ); $i++ ) {
		# Print with query string
		echo "<img src=\"folder.gif\" class=\"folder\"> &nbsp;<a href=\"?path=" . $path . "/" . $d_arr[$i] . "\">" . $d_arr[$i] . "</a><br />\n";
	}
	echo "</div>\n";
	

	echo "<div class=\"thumb-area\">\n";
	# Print file list
		$ctr = 1;
		for( $i=0; $i < count( $f_arr ); $i++ ) {
			if ((strstr($f_arr[$i],".jpg")) && (!strstr($f_arr[$i],"zyx_"))) {
				# Only print path and filename
				//if ($ctr%8==1) echo "<tr>\n";
	
				# Grab photo for class
		        $image = new hft_image($path."/".$f_arr[$i]);
		        $sz=getimagesize($path."/".$f_arr[$i]);			
	
				# Check if Thumbnail exists, if not, create one
				if (!file_exists($path."/zyx_".$f_arr[$i])) {
			        if (($sz[0] > MAX_THUMB_WIDTH) || ($sz[1] > MAX_THUMB_HEIGHT)) $image->resize(MAX_THUMB_WIDTH, MAX_THUMB_HEIGHT, '-');
			        $new_file = $path."/"."zyx_".$f_arr[$i];
			        $image->output_resized($new_file, "JPEG");   
				}
				
		        // Check if photo is oversized, if so, resize it
		        if (($sz[0] > MAX_PHOTO_WIDTH) || ($sz[1] > MAX_PHOTO_HEIGHT)) {
		        	$image->resize(MAX_PHOTO_WIDTH, MAX_PHOTO_HEIGHT, '-');
			        if (file_exists($path."/".$f_arr[$i])) unlink($path."/".$f_arr[$i]);
			        $new_file = $path."/".$f_arr[$i];
			        $image->output_resized($new_file, "JPEG");
			    }
				
				# Show Thumbnail
				$abbr = substr($f_arr[$i],0,-4);
				$abbr = substr($abbr,0,13).".jpg";
				if (MYSQL) {
					$thiscap = quickSQL("SELECT caption FROM ".MYSQL_PHOTO_TABLE." WHERE filepath='".$path."/".$f_arr[$i]."'");
					$thiscap = str_replace("\"","&#34;",$thiscap);
				}
				echo "<div class=\"thumbnail\"><a href=\"?photo=".$path."/".$f_arr[$i]."\"><img src=\"".$path."/zyx_".$f_arr[$i]."\" alt=\"".$thiscap."\" title=\"".$thiscap."\"></a><br />".(strlen($f_arr[$i])>17?$abbr:$f_arr[$i])."<br />\n";
				
				# We may want a file size. NOTE: needs $path to stat
				if (filesize($path."/".$f_arr[$i]) >= 1024) {
					# Size in kilobytes
					echo " ".round(filesize($path."/".$f_arr[$i]) / 1024, 1)." KB<br />\n";
				} elseif(filesize($path."/".$f_arr[$i]) >= 1048576) {
					# Size in megabytes
					echo " ".round(filesize($path."/".$f_arr[$i]) / 1024 / 1024, 1) . " MB<br />\n";
				} else {
					# Size in bytes
					echo " ".filesize($path."/".$f_arr[$i])." bytes<br />\n";
				}
				
				echo "</div>\n";
				//if ($ctr%8==0) echo "</tr>\n";
				$ctr++;
			}
		}
	echo "</div>\n";
	echo "</div>\n";

} // END PHOTO / DIRECTORY SWITCH

?> 

<div class="footer">2007 &copy; <a href="http://www.alanwaldron.com">Alan Waldron</a>. All Rights Reserved.</div>

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-1921914-3";
urchinTracker();
</script>

</body>
</html>