Location: PHPKode > scripts > PHP Simple Gallery Script > php-simple-gallery-script/index.php
<?PHP

/*********************************************************
This script is written by Dodo at http://regretless.com. 
Please credit me if you decide to use it! Thanks!
**********************************************************/
// Include the settings
include('settings.inc');


// This while loop is used to sort the array

$num;
$handle = opendir('.');
$index = 0;
$images;
$last_updated;
while ($file = readdir($handle)) 
{

	if($file != '.' && $file != '..')
	{
		$myfile  = explode (".", $file); // test whether is a gif file
		// test extensions!
		if($gif) {
			if($myfile[1] == 'gif' || $myfile[1] == 'GIF') // if it's a gif file
			{
			$images[$index] = $file; // then add it to the array
			$index ++;
			}
		}
		if($jpg) {
			if($myfile[1] == 'jpg' || $myfile[1] == 'JPG') // if it's a gif file
			{
			$images[$index] = $file; // then add it to the array
			$index ++;
			}
		}
		if($png) {
			if($myfile[1] == 'png' || $myfile[1] == 'PNG') // if it's a gif file
			{
			$images[$index] = $file; // then add it to the array
			$index ++;
			}
		}
	}	
}
if($images) {
sort ($images); // sort the array with the gif alphebatically
reset ($images); // reset the array
} else {
	print "<font face=\"Verdana\"><B>Warning</b><br><br>You have no image files in your directory or you didn't config the setting correctly to allow all jpg, gif, or png files! Please run this script only when those are fulfilled! Thank you!</font>";
	exit;
}


// a counter variable
$total = count($images);
if($numperpage > $total)
	$numperpage = $total;

	print "<table width=$tablewidth align=$tablealign cellpadding=0 cellspacing=0 border=0><tr><td align=center height=$tableheight>";
	print "<div class=\"num\">";

if($numperpage == $total) {
	for($k=0; $k < $numperpage; $k++) {
		$counter = $k+1;
		print "<a href=\"$PHP_SELF?num=$k\">$counter</a>&nbsp;";
} 
} elseif($num < $numperpage) {
	for($k=0; $k < $numperpage; $k++) {
		$counter = $k+1;
		print "<a href=\"$PHP_SELF?num=$k\">$counter</a>&nbsp;";
}
	
	$next = $k++;
	$next1 = $k + $numperpage;
	if($next1 >= $total) {
	$last = $total - $numperpage;
	print "<a href=\"$PHP_SELF?num=$next\"> | next $last >></a>";
	} else {
	print "<a href=\"$PHP_SELF?num=$next\"> | next $numperpage >></a>";
	}

} elseif($num >= ($total - $numperpage)) {

	$prev = $num - $numperpage;
	print "<a href=\"$PHP_SELF?num=$prev\"><< prev $numperpage | </a>";

	for($k=$num; $k < $total; $k++) {
		$counter = $k + 1;
		print "&nbsp;<a href=\"$PHP_SELF?num=$k\">$counter</a>";
	}

} elseif($num < ($total - $numperpage)) {

	$prev = $num - $numperpage;
	print "<a href=\"$PHP_SELF?num=$prev\"><< prev $numperpage | </a>&nbsp;";

	$check = $num + $numperpage;
	for($k=$num; $k < $check; $k++) {
		$counter = $k + 1;
		print "<a href=\"$PHP_SELF?num=$k\">$counter</a>&nbsp;";
	}
	
	$next = $k++;
	$next1 = $k + $numperpage;
	if($next1 >= $total) {
	$last = $total - $check;
	print "<a href=\"$PHP_SELF?num=$next\"> | next $last >></a>";
	} else {
	print "<a href=\"$PHP_SELF?num=$next\"> | next $numperpage >></a>";
	}
} else {
	print "";
}

	print "</div></td></tr><tr><td align=center>";
	
	if($num != null) {
		print "<div class=\"image\"><img src=$images[$num]></div></td></tr>";
		if($num < ($total - 1)) {
			$next = $num + 1;
			print "<tr><td align=center><div class=\"num\"><a href=\"$PHP_SELF?num=$next\">next >></a></div>";
		} else {
			$next = $num - 1;
			print "<tr><td align=center><div class=\"num\"><a href=\"$PHP_SELF?num=$next\"><< prev</a></div>";
		}
} else {
	print "<div class=\"message\">$message<br>There are total <b>$total</b> files in the gallery.</div>";
}


	print "<br><br><center><font face=verdana size=1><a href=http://daynah.net/downloads target=new>PHP simple gallery script</a> written by <a href=http://regretless.com target=new>dodo</a>.</font></center>";

	print "</td></tr></table>";

closedir($handle); 


?>
</body>
</html>

Return current item: PHP Simple Gallery Script