August 3, 2007

Super simple PHP gallery 3

Just save this as index.php and put it in a directory with a bunch of images. Images are displayed one per page (newest images first), and clicking on an image takes you to the next one.

<?
exec("ls -r|egrep -i \"\.(gif|jpg|jpeg|png)$\"", $files);
$files = array_reverse($files);
$request = $_SERVER["QUERY_STRING"];
if(!(is_numeric($request) && $request > 0 && $files[$request - 1])){
	$request = count($files);
}
$r_index = $request - 1;
$next = $r_index;
if($next==0 || !$files[$next-1]){
	$next = count($files);
}
?>
<html>
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8">
	<title>my image gallery</title>
 
	<style type="text/css" media="screen">
		a img{ border:0; }
	</style>
 
</head>
<body>
	<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
		<tr><td align="center" valign="middle"><a href="?<?=$next?>"><img src="<?=$files[$r_index]?>" /></a></td></tr>
	</table>
</body>
</html>

3 Responses

  1. 1 Billy

    Does not work.

  2. 2 joey

    Can you give me some more information about what kind of system you’re running on and what kind of error message you get?

  3. 3 bryan

    i am also having an issue getting this to work…

    not sure what i am doing wrong…have index php in folder with two images named 0.jpg, and 1.jpg….in some browsers i get broken link in other nothing shows up…

    this is it currently…

    http://www.freevisualz.com/gallery/

    thanks

Leave a Reply