Location: PHPKode > scripts > EazyGallery > eazygallery/index.php
<?php
	#########################################################################################
	#       Eazy Gallery 0.9.0 by Linkdesign.
	#       e-mail: hide@address.com
	#       GD 2 or higher required!
	#########################################################################################
	
	require('config.php');
	$table 		= 	'<center><h3>'.$title.'</h3><table border="0" cellpadding="5" cellspacing="0" align="center"><tr>';
	$mainFile 		= "index.php";						// name of this file -> change this if you change file name ex: gallery.php
	$thumbzFile		= "thumbz.php";						// name of thumbz maker file
	$fileType = array(".jpg",".jpeg", ".JPG", ".JPEG", ".png", ".PNG", ".GIF", ".gif"); // do not change those
	$imgArray = array();
	$tmpImgArray = array();

	session_start();									// Start a session.. allways before any output
	session_register("folder");							// Register session variabels
	session_register("style");
	
?>

<?
	
	
	if (isset($_GET['style']))
	{
		$_SESSION['style'] = $_GET['style'];
	}
	if (empty($_SESSION['style']))
	{
		$_SESSION['style'] = $css;
	}

	if (empty($_SESSION['folder']))				// If there's no session folder set it to root from config
	{
	  $_SESSION['folder'] = $rootFolder;
	}
	
	// Post folder can not start with / or // or ./ or ../ or .//
	if ($_GET['ch_folder']{1} == "/" || $_GET['ch_folder']{2} == "/" || $_GET['ch_folder']{0} == "/")
	{
		$tmpFolder = "";	
	}
	else	
	{
		$tmpFolder = $_GET['ch_folder'];				// Getting post folder
	}

	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
		.'<html><head><title>'.$title.'</title><link href="' . $_SESSION['style'] . '" rel="stylesheet" type="text/css">
		<script type="text/javascript" src="js/prototype.js"></script>
		<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
		<script type="text/javascript" src="js/lightbox.js"></script>
		<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
		
		</head>';
	echo '<body><table width="80%"  border="0" cellpadding="8" cellspacing="0" bordercolor="#000000"><tr>';


	if ($tmpFolder != "")
	{
		if ($tmpFolder == "..")							// If you going parrent folder
		{
			if ($_SESSION['folder'] == $rootFolder) { } // Do nothing if you are in root
			else
			{
				$tmp = strrpos($_SESSION['folder'], '/');
				$_SESSION['folder'] = substr($_SESSION['folder'], 0, $tmp); // If user is going "parrent folder" remove folder name after last slash!
			}
		}
		else
		{
			$_SESSION['folder'] = $_SESSION['folder']."/".$tmpFolder;	// else adding post folder to root folder
		}
	 }
	//////////////////////////////////////////
	// Show folders!
	// Not including some folders like:
	// "tumbz" , "css" , "images" and "."
	// Only if $bUseFolders == TRUE
	//////////////////////////////////////////
	if($bUseFolders)
	{
		print '<td width="20%" align="left" valign="top"><br><br><p>&nbsp;</p><table border="0" align="left">';

		if (!is_dir($_SESSION['folder']))				// If session folder is invalid go back to root
		{
			$_SESSION['folder'] = $rootFolder;
		}

		$handler=opendir($_SESSION['folder']);			// Reading folder
		while($tmp = readdir($handler))
		{
			if (in_array($tmp, $arrSkipFolders))		// SKIPPING folders in array
			{
			}
			else
			{
				$currentDir=$_SESSION['folder']."/".$tmp; // Setting working directory

				if (is_dir($currentDir))				// Checking if it IS a directory and printing som html
				{
					print '<TR><TD align="left">';
					if (htmlspecialchars($tmp)=="..")
					{
						print '<img src="images/up.gif">';
					}
					else
					{
						print '<img src="images/folder.gif">';
					}
					print '</TD>';
					print "<TD align=left>";
					print '<b><A HREF="'.$mainFile.'?ch_folder='.$tmp.'">';
					print htmlspecialchars($tmp) . "</A></b></TD></TR>";
				}
			}
		}
		closedir($handler);								// Closing folder
		print '</TABLE></td>';
	}

	$directory = $_SESSION['folder']."/"; 					// Slashed current folder

	if (isset($_GET['page']))								// Getting page nr for paging system
	{
		if($_GET['page'] == 1)
		{
			$pageNr = 0;
		}
		else
		{
			$pageNr = $_GET['page'] * $pageImageCount - $pageImageCount;
		}
	}
	else
	{
		$pageNr = 0;
	}

	thumbzFile($pageNr);

	function thumbzFile($pageNr)
	{
		global $directory, $fileType, $imgArray, $table, $pageImageCount, $rowImageCount, $pageNr, $mainFile, $thumbzFile, $extraInfo, $bUseJava;
		
		$dp=opendir($directory);						
		while ( false != ( $imgFile=readdir($dp) ) )			// Reading files in current directory.
		{
			if ($imgFile!="." && $imgFile!=".." )				// Skipping . and ..
			{				
				$extension = strstr($imgFile, '.');				// Getting file extension
				if( in_array($extension,$fileType) )			// Checking if it is an image file
				{
					$key = filemtime($directory.$imgFile);        // Getting modification time info
					while ($tmpImgArray[$key]) 
					{
						$key++;
					}
					$tmpImgArray[$key] = $imgFile;				// Putting images in temp array with timestamp as key 
				}
			}
		}
		if(empty($tmpImgArray)== FALSE)
		{
			if($bSort_by_date)									// If sort by date == true resorting by date
			{
				krsort($tmpImgArray, $key);
				reset($tmpImgArray);							// Resetting indicator to first possition (0)
			}

			else
			{
				sort($tmpImgArray);								// Sort alfabeticall
				reset($tmpImgArray);
			}
			foreach ($tmpImgArray as $file) 
			{
				array_push($imgArray, $file);					// Moving to "real" array
			}
		}
		echo '<td width="60%" align="left" valign="top">' . $table;

		$pageCount = ceil( count($imgArray)/$pageImageCount );	// Getting number of pages

		for($j=0;$j<$pageCount;$j++)
		{
			if( $pageNr >= ($j*$pageImageCount) && $pageNr < (($j+1) * $pageImageCount) ) // Make sure that you are working only with images on current page and not all images in directory!!!
			{
				for($i=($j*$pageImageCount);$i<(($j+1) * $pageImageCount);$i++)
				{
					if(($i%$rowImageCount == 0) && ($i > 0))
					{
						echo '</tr><tr>';						// Printing next row if previus one is full
					}
					if($i < count($imgArray)  )
					{
						$rip = "$directory$imgArray[$i]";
						$rip = str_replace(' ', '%20', $rip);	// Replacing spaces with %20
						$fileSize = filesize("$directory$imgArray[$i]");		// Getting file and iamge size for info below image
						$imageSize = GetImageSize("$directory$imgArray[$i]");
						list($foo,$width,$bar,$height) = explode("\"",$imageSize[3]);

						// Some HTML :)

                        echo '<td><table cellpadding="0" cellspacing="0" class="table_main" align="center">
						    <tr>
						      <td class="img_topleft"></td>
						      <td class="img_top"></td>
						      <td class="img_topright"></td>
						    </tr>
						    <tr>
						      <td class="img_left"></td>
						      <td class="img"><center>';

						// Linking images
						// Call javascript viewer, sending link to image and size
						echo '<a href="'.$rip.'" rel="lightbox['.$directory.']">';
						
						$thumb_src = $directory."thumbz/tb_".$imgArray[$i];

						if(is_file($thumb_src))				// Checking if thumbnail allready exist
						{
							echo '<img src="'.$thumb_src.'" border="0"></a>';
						}
						else								// Calling thumbmaker to make a thumbnail and send it to me
		 				{
						   echo '<img src="'.$thumbzFile.'?dir='.$directory.'&pict='.$imgArray[$i].'" border="0"></a>';
						}

						// Some more HTML :)
                        echo '</center></td>
					      		<td class="img_right">
								</td>
					    	</tr>
					    	<tr>
					      		<td class="img_bottomleft"></td>
					      		<td class="img_bottom"></td>
					      		<td class="img_bottomright"></td>
					    	</tr>
					        <tr>
					      		<td colspan="3" align="center">';

						// Printing extra info if needed
	  					if ($extraInfo != 0)
						{
							echo ($width).'x'.($height).' px<br>'.(int)(($fileSize/1024)+(0.5)).' kb';
						}
	  					echo '</td></tr></table>';
					}
				}
			}
			echo '</td>';
		}
		echo '</tr></table><br><br><span class="table_main">';

		// Calling navigation system below images..
		pagingList($pageNr, $pageCount);
	
	}
	
		// Change page style by setting .CSS name

	echo '</span>
	<br><br>
	<table border="0" cellspacing="4" cellpadding="4" class="table_main" >
			<tr>
			<th><div align="left">
				<form id="form1" name="form1" method="post" action="">
					Change pagestyle: &nbsp;
						<select name="styles" onchange="window.location=(\''.$mainFile.'?style=\'+this.options[this.selectedIndex].value) + \'&page='.($pageNr / $pageImageCount + 1).'\'">>
							    <option>Change style</option>
    							<option value="css/album.css">Album style</option>
								<option value="css/blue.css">Blue style</option>
								<option value="css/gold.css">Gold style</option>
								<option value="css/phpPortalen.css">PhpPortalen</option>
						</select>
				</form></div>
			</th>
		</tr>
		<tr>
			<th><div align="center"><br>
				&copy; <a href="mailto:hide@address.com">Fuad Sabanovic</a></div>
			</th>
		</tr>

	  </table><span class="table_main">';
	//include ('counter.php');
	echo '</span></td></tr></table></center><br></body></html>';

// Making navigation system below images..
function pagingList($page, $pageNumbers) 
                    
{
	global $pageImageCount, $mainFile;
	$page = $page / $pageImageCount + 1;	
	$numLinks= 6;
	$align= 'center';
	$file = $mainFile;

	// Calculate first page
	if ($pageNumbers > $numLinks)
	{
		$startLink = $page - floor($numLinks / 2);
		if ($startLink >($pageNumbers - $numLinks + 1))
		{
			$startLink = $pageNumbers - $numLinks + 1;
		}
	} 
	else $startLink = 1;
	if ($startLink < 1) $startLink = 1; 

	// Calculate last page
	$stopLink = $startLink + $numLinks - 1;
	if ($stopLink > $pageNumbers) $stopLink = $pageNumbers;

	echo "<div class=\"navigator\" style=\"text-align:$align\">\n";

	// If not a first page
	// link to first
	if ($page > 1)
	{
		 echo "<a href=\"$file?page=1\" ";
		 echo "title=\"F&ouml;rsta sidan\">First&nbsp; &laquo;</a>";
	}
	else 
		echo "<span>&laquo;</span>";

	// If first link is not a first page '...' 
	if ($startLink > 1)
	{
		echo " ... ";
	} 
	else 
		echo " -";

	// Links to pages (Not current page)
	for ($i=$startLink; $i<=$stopLink; $i++)
	{
		if ($i != $page)
		{
			echo " <a href=\"$file?page=$i\" ";
			echo ">$i</a> ";
		} 
		else 
		{
			echo " <span>( $i )</span> ";
		}
		if ($i < $stopLink) 
			echo "-";
	} 

	//  If not a last page show '...'
	if ($stopLink < $pageNumbers)
		echo " ... ";
	else 
		echo "- ";

	// If not a last page
	// link to last
	if ($page < $pageNumbers)
	{
		 echo "<a href=\"$file?page=$pageNumbers\" ";
		 echo "title=\"Sista sidan\">&raquo;&nbsp; Last</a>\n";
	} 
	else 
		echo "<span>&raquo;</span>\n";
	echo "</div>";
	}
  ?>
Return current item: EazyGallery