ini_set('error_reporting', E_ALL);
// Number of records to show per page:
$display = 8;
if (isset($_GET['np'])) { // Already been determined.
$num_pages = $_GET['np'];
} else { // Need to determine.
if ($handle = opendir('uploads/')) {
@@ $files = array();
@@ while (false !== ($file = readdir($handle))) {
@@ array_push($files, $file);
@@ }
@@ $num_records = count($files);
}
closedir($dir);
}
// Calculate the number of pages.
if ($num_records > $display) { // More than 1 page.
$num_pages = ceil ($num_records/$display);
} else {
$num_pages = 1;
}
} // End of np IF.
// Determine what # to start returning results.
if (isset($_GET['s'])) {
$start = $_GET['s'];
} else {
$start = 0;
}
// Retrieve specific group of images from array for the page.
print_r($list = array_slice($images, $start, $display));
if ($num_pages > 1) {
echo '
'; // Determine what page the script is on. $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button. if ($current_page != 1) { echo 'Previous '; } // Make all the numbered pages. for ($i = 1; $i <= $num_pages; $i++) { if ($i != $current_page) { echo '' . $i . ' '; } else { echo $i . ' '; } } // If it's not the last page, make a Next button. if ($current_page != $num_pages) { echo 'Next'; } echo '
'; } ?>