grasshopper31 Posted January 31, 2014 Share Posted January 31, 2014 In this php file im showing all the pictures in one folder (album), how can I show only 12 pictures at a time using request p, i started but dont know how to combine both together. Check where the number signs are. thanks in advance. <?php class gal_cms{ private $dir_photos = 'photos/'; private $dir_cache = 'photos/load/'; private $imgPerPage = '12'; function validImages($file){ #TODO: improve/modify according to array $ext = array('jpg','jpeg','png','gif'); if(in_array(array_pop(explode(".", $file)), $ext)){ return $image; } } function randomThumbnail($albums_location){ #TODO: finish this function //$images = scandir($albums_location); //$i = rand(2, sizeof($images)-1); $images = glob($albums_location . '*.{jpg,jpeg,png,gif}', GLOB_BRACE); $randomImage = $images[array_rand($images)]; return $randomImage; #TODO: get this image check for a thumbnail php generated then retrieve that picuture instead } function getContent(){ echo '<h2>Photo Galleries</h2>'. '<p>Here in Combbat 21, we like to capture the moments of all our memories. Whether it's during competitions or just being together as a team, we have a lot of fun times together. Time goes by really fast, so its best if you can remember all that you can. Pictures capture a moment and show them to you at a later time, reminding us of the fun seasons we had together.<br/><br/>Also check out our <a href="/">videos!</a>.</p><br/>'; #TODO: short out this algorithm if(isset($_GET['year']) AND !empty($_GET['year'])){//year input -> check input $y = $_GET['year']; if(file_exists($this->dir_photos.$y)){//if correct year input -> check for if(isset($_GET['album']) AND $_GET['album'] != ''){//year,album input -> check album input $album = $_GET['album']; if(file_exists($this->dir_photos.$y.'/'.$album)){ $p = 'photos'; } else { $p = '404'; } } else { $p = 'albums'; } } else { $p = '404'; } } else { $p = 'years'; } if($p == '404'){ $sqlError = "SELECT * FROM articles WHERE id='104'"; $result = mysql_query($sqlError) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $page = array(); $page['title'] = $row['title']; $page['content'] = $row['content']; //Be careful since content is all html echo '<h2>'.$page['title'].'</h2>'. $page['content']; } } else if($p == 'years'){ //show years $sql = "SELECT name,game_year FROM media_games ORDER BY game_year DESC"; $result = mysql_query($sql) or die(mysql_error()); $exceptions = array('2007',''); //years we did not compete while($data = mysql_fetch_array($result)){ $game_names['2007'] = ''; $game_names[$data[1]] = $data[0]; } $folders = scandir($this->dir_photos); print_r($data); Arsort($folders); //sort array by value descending order echo '<div id="gal_games">'. '<div id="gal_games_inner">'; foreach($folders as $folder){ if($folder == '.' OR $folder == '..' OR $folder == 'load'){ $forder = ''; } else { echo '<div class="gal_thumbs">'. '<a href="?year='.$folder.'">'.$game_names[$folder]. '<img src="http://combbat21.com/media/gallery/photos/thumb/'.$folder.'.jpg" alt="ThumbNail"/>'. $folder.'</a><br/>'. '</div>'; } } echo '</div></div>'; } else if($p == 'albums'){ //show albums in input:year folder $folders = scandir($this->dir_photos.'/'.$y); echo '<div id="gal_overlay"><div id="photo_content"></div></div>'; echo '<div id="gal_album">'; foreach($folders as $albumFolder){ if($albumFolder == '.' OR $albumFolder == '..'){ $albumFolder = ''; } else { $thumbnails = $this->randomThumbnail($this->dir_photos.$y.'/'.$albumFolder.'/'); //'<a href="?year='.$y.'&album='.$albumFolder.'">'.$albumFolder.'</a>'; echo ''. #TODO: remove style in img when randomthumbnail is clear '<a class="gal_albums" href="?year='.$y.'&album='.$albumFolder.'">'. '<img style="width: 130px;height:130px" src="'.$thumbnails.'" alt="THUMBNAIL"/>'. '<span class="album_name">'.$albumFolder.'</span></a>'; } } echo '</div>'; } else { $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><br/>'. '<span class="photoDate">'.$photos.'</span></div>'; } }//foreach echo '</div>'; } }//end of function }//end of class ?> Link to comment https://forums.phpfreaks.com/topic/285843-php-gallery-show-12-items-per-page/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.