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 number of files in the list to a specific number and display next using pagination. Can anybody suggest me a solution??

Thanks in advance.. :)



Please vote if you find the question useful .. :)

Written by blasteralfred

Accepted Answer

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 '<div class="file">'.$file.'</div>'; 
Written by Surreal Dreams
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki