Jump to content

Recommended Posts

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 ;)

 

Link to comment
https://forums.phpfreaks.com/topic/64876-directory-based-image-gallery-assistence/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.