grasshopper31 Posted February 1, 2014 Share Posted February 1, 2014 How can i add pagination with php to this script that shows photos in the site. i would want to show onyl 12 per page. i started but help me find out how to make this happen. thz in advance! $album_path = $this->dir_photos.$y.'/'.$album.'/'; $normalPhotos = scandir($album_path); /* $validPath = '/photos/2014/Building%20Season/test.jpg'; $exif = exif_read_data($validPath, 'IFD0', TRUE); if(isset($exif) == true){ if (@array_key_exists('DateTime', $exif)) { $strDate = $exif['DateTime']; @list( $idate, $itime ) = explode( ' ', trim($strDate) ); @list( $iyear, $imonth, $iday ) = explode( ':', $date ); $realDate = strtotime( "{$iyear}-{$imonth}-{i$day} {$itime}" ); if(filemtime($normalPhotos) != $realDate){ touch($normalPhotos,$realDate); } } } $picLink[$images.$file] = filemtime($normalPhotos); */ ######## /*$page = (isset($_REQUEST['p']) ? $_REQUEST['p'] : null); //get user p INPUT_ENV $currentpage = isset($page) ? (integer)$page : 1; //get current page.. null = 1 $totalImg = count($normalPhotos)-2; //scandir adds two items to array by default '.' and '..' $totalPages = ceil($totalImg / $this->imgPerPage); if (($currentpage > 0) && ($currentpage <= $totalPages)) { $start = ($currentpage-1) * $numperpage; for($i=$start;$i<=($numperpage+$start-1);$i++) { } }*/ ############ echo '<div id="photosCont">'; foreach($normalPhotos as $photos){ $loadedPhotos = $this->dir_cache.$y.'_'.$album.'_'.$photos; #FORMAT: photos/load/2014_Building Season_name.jpeg $urlPhotos = $this->dir_photos.$y.'/'.$album.'/'.$photos; #FORMAT: photos/load/2014_building season_name.jpg if($photos == '.' OR $photos == '..'){ $photos = ''; } else { if(!file_exists($loadedPhotos)){ $photoLink = 'image.php?y='.$y.'&a='.$album.'&i='.$photos; } else { $photoLink = $this->dir_cache.$y.'_'.$album.'_'.$photos; } echo '<div class="photosBlock">'. '<a href="'.$urlPhotos.'" target="_blank"><img src="'.$photoLink.'" alt="thumbnail"/></a></div>'; //'<span class="photoDate">'.$photos.'</span></div>'; } }//foreach echo '</div>'; } Quote Link to comment Share on other sites More sharing options...
jcbones Posted February 2, 2014 Share Posted February 2, 2014 (edited) See if this works, post back if it doesn't: (You will have to add the next/previous or page number links). Un-Tested $album_path = $this->dir_photos.$y.'/'.$album.'/'; $normalPhotos = scandir($album_path); /* $validPath = '/photos/2014/Building%20Season/test.jpg'; $exif = exif_read_data($validPath, 'IFD0', TRUE); if(isset($exif) == true){ if (@array_key_exists('DateTime', $exif)) { $strDate = $exif['DateTime']; @list( $idate, $itime ) = explode( ' ', trim($strDate) ); @list( $iyear, $imonth, $iday ) = explode( ':', $date ); $realDate = strtotime( "{$iyear}-{$imonth}-{i$day} {$itime}" ); if(filemtime($normalPhotos) != $realDate){ touch($normalPhotos,$realDate); } } } $picLink[$images.$file] = filemtime($normalPhotos); */ ######## /*$page = (isset($_REQUEST['p']) ? $_REQUEST['p'] : null); //get user p INPUT_ENV $currentpage = isset($page) ? (integer)$page : 1; //get current page.. null = 1 $totalImg = count($normalPhotos)-2; //scandir adds two items to array by default '.' and '..' $totalPages = ceil($totalImg / $this->imgPerPage); if (($currentpage > 0) && ($currentpage <= $totalPages)) { $start = ($currentpage-1) * $numperpage; for($i=$start;$i<=($numperpage+$start-1);$i++) { } }*/ ############ $offset = (!empty($_GET['offset'])) ? (int)$_GET['offset'] : 0; //get the offset from the url: echo '<div id="photosCont">'; for($i = 0,$n = $offset;$i < 12; $i++,$n++) { //changed to a for statement. if(empty($normalPhotos[$n])) { //if we hit an empty array index, break the for loop. break; //exits the for loop. } $loadedPhotos = $this->dir_cache.$y.'_'.$album.'_'.$normalPhotos[$n]; //changed to reflect array. #FORMAT: photos/load/2014_Building Season_name.jpeg $urlPhotos = $this->dir_photos.$y.'/'.$album.'/'.$normalPhotos[$n]; //changed to reflect array. #FORMAT: photos/load/2014_building season_name.jpg if($normalPhotos[$n] == '.' OR $normalPhotos[$n] == '..'){ //changed to reflect array. $normalPhotos[$n] = ''; //changed to reflext array. } else { if(!file_exists($loadedPhotos)){ $photoLink = 'image.php?y='.$y.'&a='.$album.'&i='.$normalPhotos[$n]; } else { $photoLink = $this->dir_cache.$y.'_'.$album.'_'.$normalPhotos[$n]; } echo '<div class="photosBlock">'. '<a href="'.$urlPhotos.'" target="_blank"><img src="'.$photoLink.'" alt="thumbnail"/></a></div>'; //'<span class="photoDate">'.$photos.'</span></div>'; } }//foreach //end for echo '</div>'; } Edited February 2, 2014 by jcbones 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.