Foros del Web » Programando para Internet » PHP »

Paginación para mostrar Thumbnails

Estas en el tema de Paginación para mostrar Thumbnails en el foro de PHP en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 18/05/2015, 12:25
 
Fecha de Ingreso: junio-2014
Mensajes: 14
Antigüedad: 9 años, 10 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
  #2 (permalink)  
Antiguo 19/05/2015, 08:04
Avatar de enlinea777  
Fecha de Ingreso: mayo-2008
Ubicación: frente al pc
Mensajes: 1.830
Antigüedad: 15 años, 11 meses
Puntos: 127
Respuesta: Paginación para mostrar Thumbnails

suponiendo que el checkbox es un filtro para la query deberias rescatarlo y mandarlo de nuevo por get al igual que los numeros de pagina en el apartado donde se crea el paginador o bien guardarlo en la sesion para recuperarlo luego
  #3 (permalink)  
Antiguo 20/05/2015, 02:58
 
Fecha de Ingreso: junio-2014
Mensajes: 14
Antigüedad: 9 años, 10 meses
Puntos: 0
Respuesta: Paginación para mostrar Thumbnails

Eso es lo que no sé hacer, guardar los datos del checkbox para reenviarlos.

¿Podrías ayudarme o indicarme dónde puedo ver cómo hacerlo?

Saludos!
  #4 (permalink)  
Antiguo 20/05/2015, 08:37
Avatar de enlinea777  
Fecha de Ingreso: mayo-2008
Ubicación: frente al pc
Mensajes: 1.830
Antigüedad: 15 años, 11 meses
Puntos: 127
Respuesta: Paginación para mostrar Thumbnails

Listo

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="http://www.forosdelweb.com/f18/paginacion-para-mostrar-thumbnails-1128115/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] .'?temp='.$_GET['temp'].'" 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>'
;
        }
    }
?>
  #5 (permalink)  
Antiguo 21/05/2015, 02:04
 
Fecha de Ingreso: junio-2014
Mensajes: 14
Antigüedad: 9 años, 10 meses
Puntos: 0
Respuesta: Paginación para mostrar Thumbnails

Cita:
Iniciado por enlinea777 Ver Mensaje
Listo

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="http://www.forosdelweb.com/f18/paginacion-para-mostrar-thumbnails-1128115/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] .'?temp='.$_GET['temp'].'" 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>'
;
        }
    }
?>
Muchas gracias!

Entiendo que la línea que modificaste es ésta:

Código PHP:
echo '<div class="thumb"> 
                    <a href="'
$path .'/'$files[$i] .'?temp='.$_GET['temp'].'" class="albumpix" rel="albumpix"> 
                    <img src="'
$path .'/thumbs/'$files[$i] .'" width="'.$thumb_width.'" height="'.$thumb_height.'" alt="" /> 
                    </a>   
                    </div>'

Me sale un error en la primera línea:

Notice: Array to string conversion

¿Cómo podría resolverlo?
  #6 (permalink)  
Antiguo 22/05/2015, 12:07
Avatar de enlinea777  
Fecha de Ingreso: mayo-2008
Ubicación: frente al pc
Mensajes: 1.830
Antigüedad: 15 años, 11 meses
Puntos: 127
Respuesta: Paginación para mostrar Thumbnails

primero
dice Notice no error
segundo solo dejalo pasar es una alerta sin importancia que deberias eliminar desde el php.ini en el error reporting seguramente dice E_ALL deberia decir E_ERROR

Etiquetas: formulario, html, thumbnails
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:48.