graves_it Posted March 20, 2006 Share Posted March 20, 2006 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] Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 20, 2006 Share Posted March 20, 2006 What your asking doesn't make any sense for the code that you've supplied.Please either explain better, provide more code, or both. Quote Link to comment Share on other sites More sharing options...
graves_it Posted March 20, 2006 Author Share Posted March 20, 2006 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] Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 20, 2006 Share Posted March 20, 2006 Change:[code]$lastpage = $pg +1;if($lastpage < 1){ $lastpage = $imgcount; }[/code]to:[code]$lastpage = $pg + 1;if ($lastpage > $imgcount) { $lastpage = 1; }[/code] Quote Link to comment Share on other sites More sharing options...
graves_it Posted March 20, 2006 Author Share Posted March 20, 2006 Works great, thanks Quote Link to comment 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.