Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
directory based image gallery assistence
Old 08-15-2007, 08:23 AM directory based image gallery assistence
Novice Talker

Posts: 12
Trades: 0
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
Code:
<?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
Code:
<?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
stickybomb is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-15-2007, 03:04 PM Re: directory based image gallery assistence
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
1. Could be some case sensitive stuff, try:
PHP Code:
$pattern="\.(jpg|jpeg|png|gif|bmp|JPG|JPEG|PNG|GIF|BMP)$"
I also reccomend looking into using preg_match, instead of eregi as it's newer and more efficient.
2. If your using MySQL, put the following:
'LIMIT 0 , 3'
at the end of the query you wish to limit.
The above would return everything between the first and third lines that met the query.
Change the 0 and 3 as necessary.

If not you could put something like
PHP Code:
$limit[0] = "0"
$limit[1] = "3";

$limit[2] = "0"// counter

// Stuff being returned, {
$limit[2] = $limit[2] + 1;
if(
$limit[2] >= $limit[0] or $limit[2] <= $limit[1]){
// show it
} else {
// do not show it.
}
// } 
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 08-15-2007 at 03:12 PM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Reply     « Reply to directory based image gallery assistence
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.54771 seconds with 12 queries