Olá…
muito obrigado pela ajuda…
funcionou certinho…
Agora como faço uma paginação simples ?
tipo minha tabela vai ser de 5 col. por 10 lin.
so que há umas 200 fotos no diretório…
então vou precisar paginar…
eu até baixei uns exemplo na net… e até consegui fazer carregar as imagens
só que nao funcionou o principal… a paginacao…
segue o codigo pra vc ver se é facil de acertar…
se você pode me ajudar
tem msn ou e-mail de contato mais rapido ???
Mais uma vez muito obrigado…!!
arquivo sgallery.class.php
[code]
<?
Class sGallery{
var $dirs;
var $name;
var $images = array();
var $thumbs = array();
var $nimg;
var $nthu;
var $error = array();
var $hcolor;
var $fcolor;
var $bcolor;
var $border;
var $nav;
function sGallery($name="", $d="."){
$this->dirs = $d;
$this->nimg = 0;
$this->nthu = 0;
$this->name = $name;
$this->style();
if(!($d = opendir($this->dirs."/images"))) array_push($this->error,"<b>ERROR:</b> Can't open image dir<br>");
while ($f = readdir($d)) {
if (eregi("\.jpg",$f) || eregi("\.jpeg",$f) || eregi("\.png",$f)){
array_push($this->images,"$f");
$this->nimg++;
}
}
if(!$this->nimg) array_push($this->error,"<b>ERROR:</b> No files found in image dir<br>");
if(!($d = opendir($this->dirs."/thumbs"))) array_push($this->error,"<b>ERROR:</b> Can't open thumb dir<br>");
while ($f = readdir($d)) {
if (eregi("\.jpg",$f) || eregi("\.jpeg",$f) || eregi("\.png",$f)){
array_push($this->thumbs,"$f");
$this->nthu++;
}
}
if(!$this->nthu)
array_push($this->error,"<b>ERROR:</b> No files found in thumb dir<br>");
if($this->nimg != $this->nthu)
array_push($this->error,"<b>ERROR:</b> images != thumbs<br>");
}
function style($hcolor = "NULL", $bcolor = "NULL", $fcolor = "NULL", $border=0, $nav="auto"){
$this->hcolor = $hcolor;
$this->fcolor = $fcolor;
$this->bcolor = $bcolor;
$this->border = $border;
$this->nav = $nav;
}
function show($p, $nc, $nr, $k){
if(!$p) $p = 0;
if(!$nc) $nc = 0;
if(!$nr) $nr = 0;
if(count($this->error)){
echo "<pre>Some errors were found.<br>The gallery wont run until they are solved:<br><br>";
foreach($this->error as $er)
echo $er;
echo "<pre>";
}else{
if($k == "")
$this->showpage($p, $nc, $nr);
else
$this->showimage($p, $k);
}
}
function showpage($p=0, $nc=5, $nr=5){
if($p=="") $p=0;
$nip = $nc * $nr;
$np = floor($this->nthu/$nip);
$fi = $p * $nip;
$li = (($p + 1) * $nip) - 1;
if($li >= $this->nthu) $li = $this->nthu-1;
//echo "<pre>p:$p<br>nc:$nc<br>nr:$nr<br>nip:$nip<br>np:".($np+1)."<br>fi:$fi<br>li:$li</pre>";
echo "<table border='$this->border' width='100%' cellspacing='0' cellpadding='0'><tr><td width='100%' ";
if($this->hcolor != "NULL") echo "bgcolor='#$this->hcolor'";
echo "> <b>· $this->name</b></td></tr><tr><td width='100%' ";
if($this->bcolor != "NULL") echo "bgcolor='#$this->bcolor'";
echo "><table border='0' width='100%' cellpadding='0' cellspacing='5'>";
if(eregi("\?k=",$_SERVER['REQUEST_URI'])) {
$aurl=split("?k=",$_SERVER['REQUEST_URI']);
}else if(eregi("\&k=",$_SERVER['REQUEST_URI'])) {
$aurl=split("&k=",$_SERVER['REQUEST_URI']);
}else{
$aurl[0]=$_SERVER['REQUEST_URI'];
}
$url = $aurl[0];
if(eregi("\?", $url))
$url .= "&k";
else
$url .= "?k";
for($i=$fi;$i<=$li;$i++){
if(!($i%$nc)) echo "</tr><tr>";
echo "<td align='center'>";
echo "<a ><img ></a>";
echo "</td>";
}
echo "</tr>";
$fp = 0;
$lp = $np;
$pp = $p-1; if(($p-1) < $fp) $pp = 0;
$pn = $p+1; if(($p+1) > $np) $pn = $np;
if(eregi("\?p=",$_SERVER['REQUEST_URI'])) {
$aurl=explode("?p=",$_SERVER['REQUEST_URI']); //aki tava split mas tava dando erro.. mudei pra explode.., parou o erro pelo menos
}else if(eregi("\&p=",$_SERVER['REQUEST_URI'])) {
$aurl=split("&p=",$_SERVER['REQUEST_URI']);
}else{
$aurl[0]=$_SERVER['REQUEST_URI'];
}
$url = $aurl[0];
if(eregi("\?", $url))
$url .= "&p";
else
$url .= "?p";
echo "</table></td></tr><tr><td width='100%' ";
if($this->fcolor != "NULL") echo "bgcolor='#$this->fcolor'";
echo "><p ><b>";
echo "<a ><<</a> ";
echo "<a ><</a> | ";
for($i=0;$i<=$np;$i++)
echo "<a >".($i+1)."</a> | ";
echo "<a >></a> ";
echo "<a >>></a>";
echo "</b></td></tr></table>";
}
function showimage($p, $k){
$fk = 0;
$lk = ($this->nimg-1);
$pk = $k-1; if(($k-1) < 0) $pk = 0;
$nk = $k+1; if(($k+1) >= $this->nimg) $nk = ($this->nimg-1);
if(eregi("\?k=",$_SERVER['REQUEST_URI'])) {
$aurl=split("?k=",$_SERVER['REQUEST_URI']);
}else if(eregi("\&k=",$_SERVER['REQUEST_URI'])) {
$aurl=split("&k=",$_SERVER['REQUEST_URI']);
}else{
$aurl[0]=$_SERVER['REQUEST_URI'];
}
$url = $aurl[0];
if(eregi("\?", $url))
$url .= "&k";
else
$url .= "?k";
echo "<table border='$this->border' width='100%' cellspacing='0' cellpadding='0'>";
if($this->nav == "auto" || $this->nav == "up"){
echo "<tr><td width='100%' valign='top' align='center' ";
if($this->hcolor != "NULL") echo "bgcolor='#$this->fcolor'";
echo "><table border='0' width='100%' cellpadding='0'><tr>";
echo "<td width='20%' valign='top' align='center'>[<a >First</a>]</td>";
echo "<td width='20%' valign='top' align='center'>[<a >Previous</a>]</td>";
echo "<td width='20%' valign='top' align='center'>[<a >Index</a>]</td>";
echo "<td width='20%' valign='top' align='center'>[<a >Next</a>]</td>";
echo "<td width='20%' valign='top' align='center'>[<a >Last</a>]</td>";
echo "</tr></table></td></tr>";
}
echo "<tr><td width='100%' valign='top' align='center'>";
echo "<img >";
echo "</td></tr>";
if($this->nav == "auto" || $this->nav == "down"){
echo "<tr><td width='100%' valign='top' align='center' ";
if($this->hcolor != "NULL") echo "bgcolor='#$this->fcolor'";
echo "><table border='0' width='100%' cellpadding='0'><tr>";
echo "<td width='20%' valign='top' align='center'>[<a >First</a>]</td>";
echo "<td width='20%' valign='top' align='center'>[<a >Previous</a>]</td>";
echo "<td width='20%' valign='top' align='center'>[<a >Index</a>]</td>";
echo "<td width='20%' valign='top' align='center'>[<a >Next</a>]</td>";
echo "<td width='20%' valign='top' align='center'>[<a >Last</a>]</td>";
echo "</tr></table></td></tr>";
}
echo "</table>";
}
function test(){
echo "<pre>name: $this->name<br>nimg: $this->nimg<br>nthu: $this->nthu<br>dirs: $this->dirs<br>";
echo "images:";
print_r($this->images);
echo "<br>thumbs:";
print_r($this->thumbs);
echo "</pre>";
}
}
?>[/code]
arquivo exemplo1.php
<?
# Vars
$gname = "Example 1"; # gallery Name
$dir = "."; # location of images (./images and ./thumbs should exist)
$tbgc = "aaaaaa"; # title background color (in table)
$ibgc = "fafafa"; # images and thumbs background color (in table)
$pbgc = "ccccff"; # pager background color (in table)
$pos = "down"; # position of the pager in image page (not thumb page)
$bpx = 1; # border width in pixels (for table)
$tr = 3; # thumbs per row
$tc = 3; # thumbs per col
# Note. Do not move $p and $k, they are used for paging sistem
# Require the class
require_once("sgallery.class.php");
# create a gallery object
$gallery = new sGallery($gname, $dir);
# Set a style for the gallery
$gallery->style($tbgc,$ibgc,$pbgc,$bpx,$pos);
echo "<table border='0' width='400' cellspacing='0' cellpadding='0' align='center'><tr><td width='100%'>";
$gallery->show("",$tc,$tr,"");
echo "</td></tr></table>";
?>