Jump to content

Putting a simple version of my site together, just not sure :S


Stagnate

Recommended Posts

Hello again,

 

I posted earlier thinking that if i sorted out that problem then i would be able to do the rest myself. After staring at it blankly for a few hours and reading up on "hello world" tutorials, i now realise my knowledge base is far from sufficient.

 

Ill post what im working with, its kind of a lot and hopefully some of you experts can make sense of what im wanting to do.

 

 

The top form is what I got (great) help with earlier so thats all working. The second bigger part is a script I have downloaded which turns large images into thumbnails. Now what I want to do is get my drop down on the left so that when I change it, the images for that catagory change.

 

 


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title> Photo Gallery </title>

<style type="text/css">
body {
font-size:8pt; 
color:black;
font-family:verdana,arial,helvetica,san-serif;
background-color:white;
}

td.border {
border:1px #808080 solid;
font-size:8pt;
padding:1px;
}

table {
border-collapse: collapse;
}
.page {
text-decoration:none;
}

a.page:hover {
text-decoration:underline;
color:#000099;
}

.spacer {
border:1px #808080 solid;
font-size:8pt;
background-color:#E2E2E2;
}

</style>

</head>
<body>

<!-- Dropdown Form -->

<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>

<?php ob_start();
session_start();

function listdirs($dir) {
    static $alldirs = array();
    $dirs = glob($dir . '\\*', GLOB_ONLYDIR);
    if (count($dirs) > 0) {
        foreach ($dirs as $d) $alldirs[] = $d;
    }
    foreach ($dirs as $dir) listdirs($dir);
    return $alldirs;
}

$folder = '\\images';
$dirlist = listdirs($_SERVER['DOCUMENT_ROOT'].$folder);

echo <<<htmltext
<form name="form" id="form">
        <select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">
htmltext;
for ($i=0;$i < count($dirlist);$i += 1)
{
echo "<option value=\"".basename($dirlist[$i])."\">".basename($dirlist[$i])."</option>";
}
echo <<<htmltext
  </select>
</form>
htmltext;
?>

<!-- End of Form -->






<!-- START main -->
<h3 style="text-align:center;">Photo Gallery</h3>

<div style="text-align:center;font-style:italic;font-size:8pt;">(click thumbnail to open in new window)</div>
<table border="0" cellpadding="0" cellspacing="0" align="center">

<?php
// date: 5/11/2004
// version: 1.01
// description: gallery script that creates it's own thumbnails if GD or imagemagick is installed
// license: freeware under: http://www.ricocheting.com/policy.html


// max image width/height
$config['size'] = 150;
// jpeg thumbnail image quality
$config['imagequality'] = 70;

// rows of images per page
$config['rows'] = 3;

// columns of images per page
$config['cols'] = 3;

// max page numbers to show at once
$config['maxShow'] = 10;

$config['start'] = 0;
$config['max'] = 0;
$config['page'] = isset($_GET['page'])?$_GET['page']:"0";

// folder where full size images are stored (include trailing slash)
$config['fulls']="images/";

// folder where thumbnails are to be created
$config['thumbs'] = "$config[fulls]thumb";

// method to create thumbnails. options: gd1, gd2, imagemagick
$config['imagemethod'] = "imagemagick";             

// (if imagemagick) - Path to Imagemagick "convert" program
$config['convert'] = "C:\\imagemagick\\convert.exe";
// (if imagemagick) - Path to Imagemagick "identify" program
$config['identify'] = "C:\\imagemagick\\identify.exe";




#######################################################################
//see if dir exits, if not create
if(isset($_GET['entry'])){
GetEntry();
}else{
PrintThumbs();
}
#######################################################################


#-#############################################
# desc: prints out html for thumbnails of images in directory
function PrintThumbs(){
global $config;

if (!file_exists($config['fulls'])) { 
	oops("directory <b>$config[fulls]</b> does not exist");
	die;
}
//thumb directory
if (!file_exists($config['thumbs'])) { 
	if (!mkdir($config['thumbs'], 0755)) {
		oops("Could not create thumb directory <b>$config[thumbs]</b> - check write permissions");
		die;
	}
}

   $imagelist = GetFileList($config['fulls']);
//   echo count($imagelist);

//processing for how many images to do on current page
$config['start']=($config['page']*$config['cols']*$config['rows']);
$config['max']=( ($config['page']*$config['cols']*$config['rows']) + ($config['cols']*$config['rows']) );

if($config['max'] > count($imagelist)){$config['max']=count($imagelist);}

echo "<tr><td align=\"right\" colspan=\"$config[cols]\" style=\"padding:3px;\" class=\"border\">\n";
#if there is 0 matches, show 0. otherwise show ($start+1)
if ($config['max'] == "0"){echo "Showing results <b>0 - 0</b> of <b>0</b></td></tr>\n";}
else{echo "Showing results <b>".($config['start']+1)." - $config[max]</b> of <b>".count($imagelist)."</b> entries</td></tr>\n";}


echo "<tr>";

$temp=1;
//for all the images on the page
for($i=$config['start']; $i<$config['max']; $i++){


	$thumb_image = $config['thumbs']."/".$imagelist[$i];
	$thumb_exists = file_exists($thumb_image);

	// create thumb if not exist
	if(!$thumb_exists){
		set_time_limit(30);
		$thumb_exists = ResizeImage("$config[fulls]$imagelist[$i]", $thumb_image, $config['size']);
	}

	$imagelist[$i] = rawurlencode($imagelist[$i]);
	$thumb_image = $config['thumbs']."/".$imagelist[$i];

	echo "<td valign=\"bottom\" align=\"center\" class=\"border\"><a href=\"$config[fulls]$imagelist[$i]\" title=\"$imagelist[$i]\" target=\"_blank\">"; 
	if ($thumb_exists) {
		echo "<img src=\"$thumb_image\" border=\"0\" alt=\"$imagelist[$i]\">";
	} else {
		echo "$imagelist[$i]";
	}
	echo "</a></td>\n";


	//if the max cols is reached, start new col
	if(($temp == $config['cols']) && ($i+1 != $config['max'])){
		echo "</tr><tr><td colspan=\"$config[cols]\" class=\"spacer\"> </td></tr><tr>\n";
		$temp=0;
	}
	$temp++;
}//foreach img

//if there are no results
if($config['start'] == $config['max']){
	echo "<td align=\"center\" colspan=\"$config[cols]\" class=\"spacer\">No Entries found</td>\n";
}
//if there are empty "boxes" in the row (ie; last page)
elseif($temp != $config['cols']+1){
	echo "<td align=\"center\" colspan=\"".($config['cols']-$temp+1)."\"> </td>\n";
}


echo "</tr>";
GetPageNumbers(count($imagelist));

}#-#PrintThumbs()


#-#############################################
# desc: grabs and prints filename
# returns: (bool) worked
function GetEntry(){
global $config;

if(!file_exists("$config[fulls]$_GET[entry]")){
oops("Entry does not exist");
return false;
}

echo "<a href=\"$_SERVER[HTTP_REFERER]\">Back</a><br>";
echo "<img src=\"$config[fulls]$_GET[entry]\">";


}#-#GetEntry()


#-#############################################
# desc: GetFileList
# param: [optional] directory to look through
# returns: array with list of images
function GetFileList($dirname="."){
global $config;
$list = array(); 

if ($handle = opendir($dirname)) {
	while (false !== ($file = readdir($handle))) { 
		if (preg_match("/\.(jpe?g|gif|png)$/i",$file)) { 
			$list[] = $file;
		} 
	}
	closedir($handle); 
}
sort($list);

return $list;
}#-#GetFileList()


#-#############################################
# desc: throw an error message
# param: [optional] any custom error to display
function oops($msg) {
?>
<table align=center>
<tr><td class=header>
Error:
<?
print( $msg );
?>
</td></tr>

<tr><td class=entry>
<br><?=$msg?>
<br><br>
<hr size=1 noshade width="80%" class=desc>
<center>Please hit the <a href="javaScript:history.back();"><b>back button</b></a> on your browser to try again.</center>

</td></tr></table>
<?php
}#-#oops()


#-#############################################
# desc: chooses method to resize image to correct ratio
# param: ($image) image reference of full size img to use ($newimage) what to save thumbnail as ($size) max width or height to resize to
# returns: (bool) if image was created
function ResizeImage($image, $newimage, $size) {
   global $config;
   
switch ($config['imagemethod']) {
	case "imagemagick":
		return ResizeImageUsingIM($image, $newimage, $size);
		break;
	case "gd1":
	case "gd2":
		return ResizeImageUsingGD($image, $newimage, $size);
		break;
	default:
		return false;
		break;
}
}#-#ResizeImage()


#-#############################################
# desc: resizes image if GD was used
# param: ($image) image reference of full size img to use ($newimage) what to save thumbnail as ($size) max width or height to resize to
# returns: (bool) if image was created
function ResizeImageUsingGD($image, $newimage, $size) {

list ($width,$height,$type) = GetImageSize($image);

if($im = ReadImageFromFile($image,$type)){
	//if image is smaller than the $size, make it actual $size
	if($height < $size && $width < $size){
		$newheight=$height;
		$newwidth=$width;
	}
	//if image height is larger, height=$size, then calc width
	else if($height > $width){
		$newheight=$size;
		$newwidth=($width / ($height/$size));//cast the resized width as int
	}
	//if image width is larger, width=$size, then calc width
	else{
		$newwidth=$size;
		$newheight=($height / ($width/$size));//cast the resized height as int
	}

	$im2=ImageCreateTrueColor($newwidth,$newheight);
	ImageCopyResampled($im2,$im,0,0,0,0,$newwidth,$newheight,$width,$height);

	if(WriteImageToFile($im2,$newimage,$type)){
		return true;
	}
}

return false;
}#-#ResizeImageUsingGD()


#-#############################################
# desc: resizes image using imagemagick
# param: ($image) image reference of full size img to use ($newimage) what to save thumbnail as ($size) max width or height to resize to
# returns: (bool) if image was created
function ResizeImageUsingIM($image, $newimage, $maxsize) {
global $config; 

Exec("$config[identify] -ping -format \"%w %h\" \"$image\"", $sizeinfo);

if (! $sizeinfo ) {
	return false;
}
$size = explode(" ", $sizeinfo[0]);
$width  = $size[0];
$height = $size[1];

if (!$width) {
	return false;
}

//if image is smaller than the maxsize, make it actual size
if($height < $maxsize && $width < $maxsize){
	$newheight=$height;
	$newwidth=$width;
}
else if($height > $width){
	$newheight=$maxsize;
	$newwidth= ($maxsize * $width) / $height;
}
else{
	$newwidth=$maxsize;
	$newheight=($maxsize * $height) / $width;
}

Exec("$config[convert] -geometry \"$newwidth"."x"."$newheight\" -quality \"$config[imagequality]\" \"$image\" \"$newimage\"");

return file_exists($newimage);
}#-#ResizeImageUsingIM()


#-#############################################
# desc: resizes image using imagemagick
# param: ($filename) filename of image to create ($type) int of type. 1=gif,2=jpeg,3=png
# returns: binary img
function ReadImageFromFile($filename, $type) {
$imagetypes = ImageTypes();

switch ($type) {
	case 1 :
		if ($imagetypes & IMG_GIF){
			return $im = ImageCreateFromGIF($filename);
		}
	break;
	case 2 :
		if ($imagetypes & IMG_JPEG){
			return ImageCreateFromJPEG($filename);
		}
	break;
	case 3 :
		if ($imagetypes & IMG_PNG){
			return ImageCreateFromPNG($filename);
		}
	break;
	default:
	return 0;
}
}#-#ReadImageFromFile()


#-#############################################
# desc: resizes image using imagemagick
# returns: binary img
function WriteImageToFile($im, $filename, $type) {
global $config;

switch ($type) {
	case 1 :
		return ImageGIF($im, $filename);
	case 2 :
		return ImageJpeg($im, $filename, $config['imagequality']);
	case 3 :
		return ImagePNG($im, $filename);
	default:
		return false;
}
}#-#WriteImageToFile()


#-#############################################
# sub: GetPageNumbers
# desc: gets the pages in the list
function GetPageNumbers($entries) {
global $config;

$config['totalPages']=Ceil(($entries)/($config['cols']*$config['rows']));

// echo number of pages
echo "<tr><td colspan=$config[cols] align=center height=20 class=border>Page ($config[totalPages]): ";

// echo out PREV
if( ($config['page']-1) >= 0){
echo "<a href=\"$_SERVER[sCRIPT_NAME]?page=".($config['page']-1)."\" class=page><b>«Prev</b></a>";}
// else no link
else{echo "<b>«Prev</b>";}

	// for each link, echo out page link
		$start=0; // starting image number
		$end=$config['totalPages']-1; // ending image number (total / number image on page)

	// cutoff size < page. or . page != last page (otherwise keep above values)
	if($config['maxShow'] < $config['page'] || (($config['cols']*$config['rows']*$config['maxShow'])< $entries) ){
		// if page >= cutoff size+1 -> start at page - cutoff size
		if($config['page'] >= ($config['maxShow']+1) && $config['page'] < $end-$config['maxShow']){ $start = $config['page']-$config['maxShow'];}
		elseif($end < $config['page']+$config['maxShow']+1 && $config['totalPages']-1 >= $config['maxShow']*2+1){$start = $config['totalPages']-1-$config['maxShow']*2;}
		else{$start=0;} // else start at 0

		// if page+cutoff+1 > number of pages total -> end= number of pages total
		if( $config['page']+$config['maxShow']+1 > $config['totalPages']-1 ){$end = $entries/($config['cols']*$config['rows']);}
		#&oops("$end,$config['maxShow']");
		elseif($start == 0 && $end > $config['maxShow']*2){$end = $config['maxShow']*2;}
		elseif($start == 0 && $config['totalPages'] <= $config['maxShow']*2){$end = $config['totalPages']-1;}
		else{$end = ($config['page']+$config['maxShow']);} //end = page+cutoff+1
	}


// echo out divide marker
if($start > 0){echo " ... ";}
else{echo " - ";}


// echo out each of the numbers
for($i=$start; $i<=$end ; $i++){
	if($config['page']==$i){echo "<b>[".($i+1)."]</b> \n";}
	else{echo "<a href=\"$_SERVER[sCRIPT_NAME]?page=$i\" class=page><b>".($i+1)."</b></a> \n";}
}


// echo out divide marker
if(Ceil($end) < $config['totalPages']-1){echo " ... ";}
else{echo " - ";}

// echo out NEXT
if( ($config['page']+1) <= $config['totalPages']-1){
echo "<a href=\"$_SERVER[sCRIPT_NAME]?page=".($config['page']+1)."\" class=page><b>Next»</b></a> ";}
// else no link
else{echo " <b>Next»</b> ";}

echo "</td></tr>";
}#-#end GetPageNumbers()

?>

<!-- END main -->
</td></tr></table>

</body>






 

 

Thanks for looking through my newbie issues.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.