Jump to content
Xisto Corporation
Sign in to follow this  

Displaying Files Of A Directory

Recommended Posts

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";

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.