HOME       >>       Programming

Displaying Files Of A Directory


apple

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




anonymal

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.

electron

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.



VIEW ORIGINAL REGISTER GET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.