PHP - Ayuda con Paginación con Thumbnails

 
Vista:
sin imagen de perfil

Ayuda con Paginación con Thumbnails

Publicado por PHPera (1 intervención) el 19/05/2015 13:02:16
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/ y sé que el problema está en los href de la función print_pagination de PHP, pero no sé cómo solucionarlo...

¿Podría ayudarme alguien?

Muchas gracias.

Saludos,

Jennifer

--------------------------------------------

Código HTML:

1
<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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?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) == 0 ) {
            echo $path;
            echo 'There are no photos in this album!';
        } else {
            $numPages = ceil( count($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>';
        }
    }
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder