Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/05/2015, 12:25
Jenn90
 
Fecha de Ingreso: junio-2014
Mensajes: 14
Antigüedad: 9 años, 11 meses
Puntos: 0
Paginación para mostrar Thumbnails

Hola a tod@s!

Llevo una semana dándole vueltas al tema de la paginación con formularios PHP y no saco nada en claro.

Al enviar un formulario con un checkbox he de cargar los thumbnails de las imágenes. La primera página la carga sin problemas (las primeras 15 imágenes), pero al hacer click para que me dirija a la página 2, no consigo guardar el valor del checkbox para que me cargue las 15 siguientes.

El código para generar los thumbnails lo saqué de http://www.foliopages.com/.

Lo pongo a continuación.

Código HTML:

Código:
  <form action="" name="form" method="GET"> <input type="checkbox" id="C" name="temp[]" value="C"> <span>Multitemporal</span><button type="submit" class="btn btn-default btn-xs">Enviar</button></form>
Código PHP:

Código PHP:
<?php
if (!(isset($_GET['temp']))) {
                        echo
"no existe";
                    } else{ 
                        foreach (
$_GET['temp'] as $temp) {
                          
                        }
                        
                        if(
$temp=="A") {

                        } elseif (
$temp=="C") {

                            
$path 'images'# Directorio donde están las imágenes
                            
echo '<table>';
                            echo
'<tr>';

                            
temp($path$temp);
                        }
                    }

    function 
make_thumb($folder,$src,$dest,$thumb_width) {

        if (
preg_match("#([a-zA-Z0-9_\-\s]+)\.(jpg|JPG)#is",$src)){

            
$source_image imagecreatefromjpeg($folder.'/'.$src);
        } elseif (
preg_match("#([a-zA-Z0-9_\-\s]+)\.(png|PNG)#is",$src)){

                
$source_image imagecreatefrompng($folder.'/'.$src);
        }

        
$width imagesx($source_image);
        
$height imagesy($source_image);

        
$thumb_height floor($height*($thumb_width/$width));

        
$virtual_image imagecreatetruecolor($thumb_width,$thumb_height);

        
imagecopyresampled($virtual_image,$source_image,0,0,0,0,$thumb_width,$thumb_height,$width,$height);

        
imagejpeg($virtual_image,$dest,100);

    }

    
// display pagination
    
function print_pagination($numPages,$currentPage,$temp) {

       echo 
'Page '$currentPage .' of '$numPages;
       
       if (!isset(
$temp)) {
           echo 
"no existe";
       } else {
            if (
$numPages 1) {
                echo 
'&nbsp;&nbsp;';

                if (
$currentPage 1) {
                    
$prevPage $currentPage 1;
                    
                    echo 
'<a href="'$_SERVER['PHP_SELF'] .'?p='$prevPage.'">&laquo;&laquo;</a>';
                }       

                for( 
$e=0$e $numPages$e++ ) {
                    
$p $e 1;

                    if (
$p == $currentPage) {        
                        
$class 'current-paginate';
                    } else {
                        
$class 'paginate';
                    } 
                    echo 
$_SERVER['PHP_SELF'];
                    
//echo '<a href="campanas.php?temp%5B%5D=C&calendar=Introduce+una+fecha...">1</a>';
                    
echo '<a class="'$class .'" href="'$_SERVER['PHP_SELF'] .'?p='$p .'">'$p .'</a>';
                }

                if (
$currentPage != $numPages) {
                    
$nextPage $currentPage 1;    
                    echo 
'<a href="'$_SERVER['PHP_SELF'] .'p='$nextPage.'">&raquo;&raquo;</a>';
                }
                
            }
       }
    }

    function 
temp($path$temp) {

        
$itemsPerPage '16';         // number of images per page    
        
$thumb_width  '120';        // width of thumbnails
        
$thumb_height '85';         // height of thumbnails
        
$src_files    scandir($path); // files in current folder
        
$extensions   = array(".jpg",".png",".gif",".JPG",".PNG",".GIF"); // allowed extensions in photo gallery

        
echo '<div class="gallery">';
        
        
$files = array();

        foreach(
$src_files as $file) {

            
$ext strrchr($file'.');

            if(
in_array($ext$extensions)) {

                
array_push$files$file );          

                if (!
is_dir($path.'/thumbs')) {
                    
mkdir($path.'/thumbs');
                    
chmod($path.'/thumbs'0777);
                    
//chown($path.'/thumbs', 'apache'); 
                
}

                
$thumb $path.'/thumbs/'.$file;

                if (!
file_exists($thumb)) {
                    
make_thumb($path,$file,$thumb,$thumb_width); 
                }                                
            }
        }

        if ( 
count($files) == ) {
            echo 
$path;
            echo 
'There are no photos in this album!';
        } else {
            
$numPages ceilcount($files) / $itemsPerPage );

            if(isset(
$_GET['p'])) {

                
$currentPage $_GET['p'];

                if(
$currentPage $numPages) {
                    
$currentPage $numPages;
                }
            } else {
                
$currentPage=1;
            } 

            
$start = ( $currentPage $itemsPerPage ) - $itemsPerPage;

            for( 
$i=$start$i<$start $itemsPerPage$i++ ) {

                if( isset(
$files[$i]) && is_file$path .'/'$files[$i] ) ) { 

                    echo 
'<div class="thumb">
                    <a href="'
$path .'/'$files[$i] .'" class="albumpix" rel="albumpix">
                    <img src="'
$path .'/thumbs/'$files[$i] .'" width="'.$thumb_width.'" height="'.$thumb_height.'" alt="" />
                    </a>  
                    </div>'

                } else {

                    if( isset(
$files[$i]) ) {
                        echo 
$files[$i];
                    }
                }
            }


            echo 
'<div class="clear"></div>';

            echo 
'<div class="p5-sides">
            <div class="float-left">'
.count($files).' images</div>
            <div class="float-right" class="paginate-wrapper">'
;

            if (
$temp="C") {
                
print_pagination($numPages,$currentPage,$temp);
            }

            echo 
'</div>
            <div class="clearb10">
            </div>'
;
        }
    }
?>
Saludos,

Jennifer