Jump to content


Photo

If statements


  • Please log in to reply
4 replies to this topic

#1 graves_it

graves_it
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 20 March 2006 - 12:24 AM

Using a simple php array to move thru files. The problem I am havin is if the last file, i dont now of a way to go back to the first.

Here is the code I am using.


<?
$Files = array(); $Files[] = ""; $dirfiles =  opendir($dir); $imgcount = 1;

$imgcount = $imgcount-1;
if($pg == "" or $pg > $imgcount or $pg < 1){ $pg = $imgcount; }
$imagesource = $dir . $Files[$pg];
$imageinfo = getimagesize($imagesource);
$imageheight = $imageinfo[1];
$imagewidth = $imageinfo[0];

$lastpage = $pg +1;
if($lastpage < 1){ $lastpage = $imgcount; }

$nextpage = $pg -1;
if($nextpage < 1){ $nextpage = $imgcount; }
?>


#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 20 March 2006 - 12:37 AM

What your asking doesn't make any sense for the code that you've supplied.

Please either explain better, provide more code, or both.

#3 graves_it

graves_it
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 20 March 2006 - 12:42 AM

Here is all the code. This is a photo gallery that uses the date to order the pictures. Let say there are 3 picture. When you are on 3 and use $lastpage it goes to ?pg=4 instead of the begeinning ?pg=1.


<?
$Files = array(); $Files[] = ""; $dirfiles =  opendir($dir); $imgcount = 1;
$cdate = date("Ymd"); $pg = $_GET['pg'];
if (! $dirfiles)
die('Can Not Find Any Images' . $dir);
while ($Filename = readdir($dirfiles))
{
    if($datedriven == true) {$fulldate = substr($Filename, 0, 8); }else{$fulldate = 0;}
    $fulldate = substr($Filename, 0, 8);
    if ($Filename == '.' || $Filename == '..' || $fulldate > $cdate)
    continue;
    $imgcount++;
    $Files[] = $Filename;
}
sort($Files);
$imgcount = $imgcount-1;
if($pg == "" or $pg > $imgcount or $pg < 1){ $pg = $imgcount; }
$imagesource = $dir . $Files[$pg];
$imageinfo = getimagesize($imagesource);
$imageheight = $imageinfo[1];
$imagewidth = $imageinfo[0];
if($datedriven == true)
{
    $month = substr($Files[$pg], 4, 2);
    $day = substr($Files[$pg], 6, 2);
    $year = substr($Files[$pg], 0, 4);
    $imagecolor = "#" . substr($Files[$pg], 12,6);
}else{
    $month = "";
    $day = "";
    $year = "";
    $imagecolor = $defaultbackcolor;
}

$lastpage = $pg +1;
if($lastpage < 1){ $lastpage = $imgcount; }

$nextpage = $pg -1;
if($nextpage < 1){ $nextpage = $imgcount; }
?>


#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 20 March 2006 - 01:00 AM

Change:

$lastpage = $pg +1;
if($lastpage < 1){ $lastpage = $imgcount; }

to:

$lastpage = $pg + 1;
if ($lastpage > $imgcount) { 
    $lastpage = 1; 
}


#5 graves_it

graves_it
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 20 March 2006 - 01:05 AM

Works great, thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users