VIew files in directory with pagination - php

前端 未结 6 1755
遇见更好的自我
遇见更好的自我 2020-12-30 15:06

I want to display files in my directory in browser. I know that this is possible using @opendir and readdir .. But what I want is to limit the numb

6条回答
  •  攒了一身酷
    2020-12-30 15:45

    Maybe something like this?

    $page = 1;
    $resultsPerPage = 10;
    
    $files = array();
    
    while(($obj = readdir($dir))) {
        $files[] = $obj;
    }
    
    $limit = $page * $resultsPerPage;
    ($limit > count($files)) ? $limit = count($files) : $limit = $limit;
    for($i = ($limit - $resultsPerPage); $i < $limit; $i++) {
       echo($files[$i];
    }
    

    And then have your nav buttons modify the page number.

提交回复
热议问题