Honesty Rocks! truth rules.

Displaying Files Of A Directory

HOME      >>       Programming


I want to display the contents of a directory..
i have the following code..
It gives the output in one column only... like

Since there are lot of files so this column gets very long..i want to display the x number of files in each column..
like if there are 22 files..
file 1 file 11 file 21
file 2 . file 22
file 3 ..
file 10 file 20

This was just an example..I know it can be done by using <td> but i dont know how to do it with loop.
Please help me.

$dir = './';
$handle = opendir($dir);
//$count = 0;
while (($file = readdir($handle)) !== false)
if ( !in_array($file, array('.', '..') ) )
echo basename($file, '.php') ."<br />\n";

//print "$count";


Here's another one:


function dirList ($directory)



// create an array to hold directory list

$results = array();


// create a handler for the directory

$handler = opendir($directory);


// keep going until all files in directory have been read

while ($file = readdir($handler)) {


// if $file isn't this directory or its parent,

// add it to the results array

if ($file != '.' && $file != '..')

$results[] = $file;



// tidy up: close the handler



// done!

return $results;



But I want somebody to help me on haw to delimit the number of items I want to be displayed in this code. I mean I want to put Next and Previous buttons. dividing the results through paging.


Thats simple. You could limit it with the number of files you want to display and then using the GET VAR get the page number accordingly and then show the results.