Stickybomb Posted August 14, 2007 Share Posted August 14, 2007 i am try to create a simple script that will read a directory, get the images in it and write them to the page. It would also seperate them in to multiple pages. This is what i have so far gal.php <?php $limit=5; function returnimages($dirname) { $pattern="\.(jpg|jpeg|png|gif|bmp)$"; $curimage=0; if($handle = opendir($dirname)) { while(false !== ($file = readdir($handle))){ if(eregi($pattern, $file)){ $galleryarray[$curimage]=$file; $curimage++; } } closedir($handle); } return($galleryarray); } ?> page to display the images <?php include('gal.php'); if(isset($_GET['year'])){$year=$_GET['year'];}else{$year=2001;} $image = array(); $image = returnimages('IFAIphotos/'.$year); $limit = 5; $images = count($image); $totalrows = ceil($images/2); $numofpages = ceil($totalrows / $limit); if(isset($_GET['page'])){$page=$_GET['page'];}else{$page=1;} $limitvalue = ($page-1) * $limit; ?> <p align="center"><img src="IFAIphotos/<?=$year;?>/<?=$year;?>_logo.jpg" alt="IFAI <?=$year;?>" /></p> <?php for($i=1;$i==$images;$i++){ echo '<p align="center"><img src="IFAIphotos/'.$year.'/'.$image[$i].'" alt="1" width="150" hspace="5" />'; $i++; echo '<p align="center"><img src="IFAIphotos/'.$year.'/'.$image[$i].'" alt="1" width="150" hspace="5" /></p>'; } ?> <p align="center"><span class="pagenav"> <?php if($numofpages!=1){ if($page!=1){ $pageprev = ($page-1); echo '<a href="preevent.php?year='.$year.'&page='.$pageprev.'">PREV</a> '; } for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo('<a href="preevent.php?year='.$year.'&page='.$i.'">'.$i.'</a> '); } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = ($page+1); echo('<a href="preevent.php?year='.$year.'&page='.$pagenext.'">NEXT</a>'); }else{ echo(""); } } ?> basically the problems i am having are 1. i can not seem to get the filename for each image. The for loop to echo the images displays nothing 2. I know how to do it using a database driven system but am stumped on how to limit the rows of images per page for it to be pageinated. can someone please lend some assistence on this thanks Quote Link to comment https://forums.phpfreaks.com/topic/64876-directory-based-image-gallery-assistence/ Share on other sites More sharing options...
Stickybomb Posted August 15, 2007 Author Share Posted August 15, 2007 bump! any help plz Quote Link to comment https://forums.phpfreaks.com/topic/64876-directory-based-image-gallery-assistence/#findComment-324544 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.