Jump to content
xisto Community
Sign in to follow this  
apple

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
file1
file2
file3
file4
.
.
.
.
.

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..
then
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";
//$count++;

}
}
//print "$count";
closedir($handle);



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

closedir($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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
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.