VIew files in directory with pagination - php

前端 未结 6 1754
遇见更好的自我
遇见更好的自我 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:56

    You could use scandir to read all the contents of the directory into an array. Then output the contents of the array based on the pagination value.

    $offset = 10; //get this as input from the user, probably as a GET from a link
    $quantity = 10; //number of items to display
    $filelist = scandir('/mydir');
    
    //get subset of file array
    $selectedFiles = array_slice($filelist, $offset-1, $quantity);
    
    //output appropriate items
    foreach($selectedFiles as $file)
    {
        echo '
    '.$file.'
    '; }

提交回复
热议问题