简体   繁体   中英

How to use Glob Brace for listing only folders with pagination

I want to know that , how we can use php's glob brace function to open a dir and scan all folders from it and then , show it with Pagination (Page1,Page2,etc). And how to limit results per page?

Based on: pagination of php glob page

$folders = glob("*", GLOB_ONLYDIR);
usort($folders, function ($a, $b) {
return filemtime($b) - filemtime($a);
});

$record_count  = 20;
$total_pages   = ceil(count($folders)/$record_count);
$page          = $_REQUEST['page']; ///make it dyanamic :: page num
$offset        = ($page-1)*$record_count;
$folders_filter  = array_slice($folders, $offset,$record_count);

foreach ($folders_filter as $folder) {
echo "$folder <br/>";
}

if($total_pages > 1){
   if($page != 1){
      echo '<a href="thispage.php?page='.($page-1).'">Prev</a>';
   }
   if($page != $total_pages){
      echo '<a href="thispage.php?page='.($page+1).'">Next</a>';
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM