• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

php directory listings

lucifer

NLC
NLC
how can I get a directory listing in PHP

I can check things are directories but not do anything with them :mad: :mad:
 
Something like this? :rolleyes:
PHP:
function list_dir($dirname) 
{ 
if($dirname[strlen($dirname)-1]!='\\') 
$dirname.='\\'; 
static $result_array=array(); 
$handle=opendir($dirname); 
while ($file = readdir($handle)) 
{ 
if($file=='.'||$file=='..') 
continue; 
if(is_dir($dirname.$file)) 
list_dir($dirname.$file.'\\'); 
else 
$result_array[]=$dirname.$file; 
} 
closedir($handle); 
return $result_array; 
}
 
Chapter XVL Directory functions

now why couldn't I find that??

thanks though your code was a little buggy ;)
 
try this:

Code:
<?
$dir="."; // directory to index
$a=opendir($dir);
while($b=readdir($a))
{
      if(ereg("^\.",$b)) continue;
      echo "<a href=\"$b\">$b</a><br>";
}
closedir($a);
?>
 
Last edited:
Back
Top