Jump to content
php.lv forumi

attēlu sadalīšana pa lapām


ArnisR

Recommended Posts

Tātad uz servera ir direktorija, kas satur daudzus attēlus. Ar PHP visi attēli tiek nolasīti pa tiešo no tās mapītes un izvadīti. Tad kā varētu sadalīt attēlus pa lappusēm, ja tie sakrājas lielā daudzumā? Ir kādas idejas?

Link to comment
Share on other sites

Bildes tiek attēlotas šādi:

 

<?php

if ($handle = opendir('img/')) {

   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != "..") {

       printf('<img class="picture" src="img/%s" alt="img"/>', $file);

       }
   }
   closedir($handle);
}

?>

Edited by ArnisR
Link to comment
Share on other sites

vienkāršāk būtu ielasīt masīvā un tad masīvu parādīt lapaspusēs..

piemērs:

<?php
$avgal[$gallery] = isset($gallery) ? $avgal[$gallery] : $avgal[1];
$path = "subpages/galerija/{$avgal[$gallery]}/";
$pictures = glob($path."images/*.jpg");
$p = $p = isset($_GET['p'])? (((int)$_GET['p'] == 0) ? 1 : (int)$_GET['p']) : 1;
$perpage = 25;
$start = ($p-1)*$perpage;
$end = $start+$perpage;

?>
<div id="gallery">
 <div class="galleryrow">
   <?
   $pics = array_slice($pictures,($p-1)*$perpage,$perpage);
   $i = 1;
   foreach($pics as $pic){
     print '<div class="gallerydata">
               <table>
                 <tr valign="middle">
                   <td>
                     <a href="'.$pic.'" rel="lightbox"><img src="'.cropmaker($pic, 80, 0.2, $avgal[$gallery]).'"/>
                     </a>
                   </td>
                 </tr>
               </table>
             </div>';

     if($i % 5  == 0){ print '</div><div class="galleryrow">';}
     $i++;
   }
   ?>
 </div>
 <?
  echo drawpages(count($pictures), $perpage,"page=portfolio&gallery=".htmlspecialchars($gallery));?>
</div>

 

draw pages no defektologs.lv

nedaudz pielabots no manis.

function drawpages($count, $perpage, $lapa, $offset = 5){
$pages = ceil($count/$perpage);
if($pages < 2) return '';
$r = '<ul class="pages" style="clear:left;">';
$page = (empty($_GET['p']) || $_GET['p'] < 2) ? 1 : (int)$_GET['p'];
$first = $page >= $offset+1 ? $page-$offset : 1;
$last = $page <= $pages-$offset ? $page+$offset : $pages;
if($page > 1) $r.= sprintf('<li><a href="?%s&p=1">«</a></li><li><a href="?%s&p=%d"><</a></li>',$lapa, $lapa, $page-1);
for($i = $first; $i <= $last; $i++) $r.= sprintf('<li%s><a href="?%s&p=%d">%d</a></li>', $page==$i ? ' class="active"' : '', $lapa, $i, $i);
if($page < $pages) $r.= sprintf('<li><a href="?%s&p=%d">></a></li><li><a href="?%s&p=%d">»</a></li>', $lapa, $page+1, $lapa, $pages);
$r.= '</ul>';
return $r;
}

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...