Jump to content

If statements


graves_it

Recommended Posts

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.


[code]<?
$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; }
?>[/code]
Link to comment
Share on other sites

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.


[code]<?
$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; }
?>[/code]
Link to comment
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.