javascript - PHP script: Display images from folder with limit and <next> navigation -
here current php script display images folder table. however, there lot of images , load time slow. how can limit number of images displayed , create dynamic navigation feature? thanks!!
<?php $files = glob("images/*.*"); ($i = 1; $i < count($files); $i++) { $image = $files[$i]; $supported_file = array( 'gif', 'jpg', 'jpeg', 'png' ); $ext = strtolower(pathinfo($image, pathinfo_extension)); if (in_array($ext, $supported_file)) { echo '<td><a href="' . $image . '"><img src="' . $image . '" alt="random image" width=200 /></a></td>'; } if ($i % 5 === 0) { echo "</tr><tr>"; } } ?>
you save $files variable in $_session array. like
if (empty($_session['files'])) { $files = glob("images/*.*"); ... code cleaning $files array based on extension ... $_session['files'] = $files; } else { $files = $_session['files']; } then check size of $files , create links based on size want.
<a href="/whatever?page=2">2</a> then use $_get['page'] variable determine desired set of images display.
Comments
Post a Comment