I need help with my gallery script.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

well, give us the source for the script then...
pepsidemon
Forum Newbie
Posts: 13
Joined: Sun Apr 04, 2004 10:21 pm

Post by pepsidemon »

Here it is:

Code: Select all

<?php
## Admin options - edit as you wish
# Allow admin area? 1=yes, 0=no
 $adminarea = 1;
# Enter the password you want for the administator
 $adminpassword = "cookiemoth";
# Do you want to have maximum file sizes, 1 = yes, 0 = no
 $filesizes = 0;
# If you answered 1 to the above please fill in the below (in KB)
 $maxthumbfilesize = "20";
 $maximagefilesize = "400";
# Enter what should be the begining of all your thumbs, ie "tn_"
 $key = "tn_";
##########################################
## Format Variables, edit if you want!! ##
##########################################
# Enter the Name of your image gallery, i.e DBZ Gallery
 $galleryname = "My Dog";

## Image variables
# Enter how many images you want to be displayed per page
 $limit = 15;
##################

# font face, font size(in points), font color, link color,
 $fontface = "arial";
 $fontsize = 8;
 $fontcolor = "666666";
 $linkcolor = "666666";

## Table variables
# Enter the border size in pixels and the border color in hex
 $border=1;
 $bordercolor="666666";
# enter how wide in px you want the space around the image to be
 $cellpadding = 2;
# Enter how many columns in the table you want there to be before
# It starts a new row
 $columns=5;
# Now enter the bg of the table
 $tablebg="cccccc";
# Now the width of the table
 $tablewidth = "600";
#################


##########################################
##  Pretty Complicated Leave alone!!!!  ##
##########################################

	if(phpversion()>4.2){
	 $HTTP_HOST = $_SERVER["$HTTP_HOST"];
	 $postpassword = $_POST["postpassword"];
	}

 include("header.inc");
	if($view){
	 echo "<table cellpadding="$cellpadding" cellspacing="$border" bgcolor="#$bordercolor" style="font-size: ${fontsize}pt; color: #$fontcolor; font-family: $fontface" width="$tablewidth">";
		if(!file_exists($view)){
		 echo "<tr bgcolor="$tablebg"><td>The file does not exist</td></tr>";
		} else {
		 $imagesize = getimagesize($view);
		 $stamp = filemtime($view);
		 $filesize = filesize($view);
		 $filesize = number_format($filesize/1024,"2",".","'");
		 $date = date("dS of F, Y \@ H:i",$stamp);
		 echo "<tr bgcolor="$tablebg"><td align="center"><img src="$view"></td></tr>";
		 echo "<tr><td align="center"><font color="$tablebg"><b>Image Details</b></font></td></tr>";
		 echo "<tr bgcolor="$tablebg"><td><b>File Name:</b> /$view<br><b>Width:</b> $imagesize[0] pixels<br>\n<b>Height:</b> $imagesize[1] pixels<br><b>File Size:</b> $filesize KB<br><b>Uploaded:</b> $date</td></tr>";
		}
	 echo "</table>";
	} else {
		if(!$page){
		 $page=1;
		}
		if(!$reverse){
		 $reverse="no";
		}
		if(!$sort){
		 $sort="abc";
		}
	 $page -= 1;
	 $page *= $limit;
		function getaccess ($file) {
		 $stamp = filemtime($file);
		 return $stamp;
		}
			while ($file = readdir($directory)) {
				if (is_dir($dir.$slash.$file) || (strtolower(substr($file, 0,3)) == $key && (strstr($file, ".gif") || strstr($file, ".jpg") || strstr($file, ".png") || strstr($file, ".bmp") || strstr($file, ".jpeg")) ) ) {
					if($file != ".." && $file != "."){
						if($sort=="date"){
						 $stamp = getaccess($dir.$slash.$file);
						 $array .= "$stamp||$file||\n";
						} else {
						 $lowercase = strtolower($file);
							if(is_dir($dir.$slash.$file)){
							 $array .= "_00_$lowercase||$file||\n";
							} else {
							 $imagecount++;
							 $array .= "$lowercase||$file||\n";
							}
						}
					}
				}
			}
	 closedir($directory);
	 $array = substr($array, 0,-1);
	 $files = explode("\n", $array);
	 echo "
	<body text="$fontcolor" link="$linkcolor" vlink="$linkcolor" style="font-family: $fontface">
	<table cellpadding="$cellpadding" cellspacing="$border" bgcolor="#$bordercolor" style="font-size: ${fontsize}pt; color: #$fontcolor" width="$tablewidth">";
		if($message){
		 echo " <tr bgcolor="$tablebg">\n  <td colspan="$columns">\n   $message\n  </td>\n </tr>\n";
		}
		if(!$imagecount){
		 $imagecount=0;
		}
	echo " <tr>
	  <td bgcolor="$tablebg" colspan="$columns">
	   <b>Total Images:</b> $imagecount<br>\n<b>Go to Page:</b> ";
		for ($i = 1; $i <= count($files); $i+=$limit) {
			if (!$files[$i]) {
			   continue;
			}
		 $a++;
		 echo "   <a href="$PHP_SELF?page=$a&sort=$sort&dir=$dir">$a</a> \n";
		}
	 $newpage = $page + 1;
	 echo "  </td>
	 </tr>
	 <tr>
	  <td bgcolor="$tablebg" colspan="$columns">
	   <b>Sort:</b> Filename: <a href="$PHP_SELF?page=$newpage&sort=abc&reverse=no&dir=$dir">Ascending</a> <a href="$PHP_SELF?page=$newpage&sort=abc&reverse=yes&dir=$dir">Descending</a> | Date: <a href="$PHP_SELF?page=$newpage&sort=date&reverse=no&dir=$dir">Ascending</a> <a href="$PHP_SELF?page=$newpage&sort=date&reverse=yes&dir=$dir">Descending</a>
	  </td>
	 </tr>
	 <tr bgcolor="$tablebg">\n";
		if($sort=="abc"){
			if($reverse=="yes"){
			 rsort($files, SORT_STRING);
			} else {
			 sort($files, SORT_STRING);
			}
		} else {
			if($reverse=="yes"){
			 rsort($files, SORT_NUMERIC);
			} else {
			 sort($files, SORT_NUMERIC);
			}
		}
	
		for ($i = $page; $i < $page+$limit; $i++) {
			if (!$files[$i]) {
			   continue;
			}
		 $cols++;
		 $image = explode("||",$files[$i]);
		 $link = $PHP_SELF."?view=".$dir.$slash.eregi_replace($key,"",$image[1])."" target="$image[1]";
	 unset($deletelink);
	 $dirtest = ereg_replace("_00_","",$image[1]);
		if($adminarea==1 && !$loginerror){
			if(!is_dir($dir.$slash.$dirtest)){
			 $deletelink = "<br><a href="$PHP_SELF?delete=$dir$slash$image[1]">[delete]</a>";
			}
		}
		if($dir){
		 $image[1] = "$dir/".$image[1];
		}
	 unset($dirtitle);
		if(is_dir($dir.$slash.$dirtest)){
		 $image = "folder.gif" width="45";
		 $link = "$PHP_SELF?dir=$dir$slash$dirtest";
		 $dirtitle = "<br>$dirtest";
		} else {
		 $image = $image[1];
		}
		 echo "  <td align="center"><a href="$link"><img src="$image" border="0">$dirtitle</a>$deletelink</td>\n";
			if($cols==$columns && ($i+1) != ($page+$limit)){
			 echo " </tr>\n <tr bgcolor="$tablebg">\n";
			 $cols=0;
			}
		}
		if($adminarea==1){
			if($loginerror){
			 echo "<tr bgcolor="$tablebg"><form action="$PHP_SELF?loginsubmit=yes" method="post"><td colspan="$columns" align="center"><B>Login</B><br>Password: <input type="password" name="postpassword"> <input type="submit" value="Login"></td></form></tr>";
			} else {
			 echo "<tr bgcolor="$tablebg"><form action="$PHP_SELF?upload=yes&dir=$dir" method="post" enctype="multipart/form-data"><td colspan="$columns" align="center"><B>Admin: Upload an image</B><br>Thumbnail: <input type="file" name="postthumbnail"><br>Full Size Images: <input type="file" name="postimage"><br><input type="submit" value="Upload">";
				if($dir){
				 echo "<br>If you plan on uploading to this directory you will need to chmod it to 777";
				}
			 echo "</td></form></tr>";
			}
		}
	 echo " </tr>\n <tr>\n  <td colspan="$columns" bgcolor="$tablebg">\n  Image Gallery v.3.0 created by Deano of <a href="http://www.naget.com">NAGET Solutions</a><br><a href="$PHP_SELF">Back to image Index</a>\n  </td>\n </tr>\n";
	 echo "</table>\n";
	}
 include("footer.inc");
?>
pepsidemon
Forum Newbie
Posts: 13
Joined: Sun Apr 04, 2004 10:21 pm

Post by pepsidemon »

Heh,I couldn't figure it out.
Post Reply