PDA

View Full Version : php directory listings



lucifer
May 30th, 2001, 21:26
how can I get a directory listing in PHP

I can check things are directories but not do anything with them :mad: :mad:

meow
May 30th, 2001, 21:45
Something like this? :rolleyes:


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

lucifer
May 30th, 2001, 22:23
Chapter XVL Directory functions

now why couldn't I find that??

thanks though your code was a little buggy ;)

keith
May 30th, 2001, 22:27
try this:



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

meow
May 30th, 2001, 22:37
Originally posted by lucifer
thanks though your code was a little buggy ;)

Well what do you expect after 1 day of studies? :eek: ;)

lucifer
May 30th, 2001, 22:52
hey it solved my problems :D

meow
May 30th, 2001, 23:04
http://www.google.com/search?q=directory+listing+in+php&btnG=Google+Search
#1 refers to http://www.php.net/manual/ref.dir.php
I don't want you to think I'm smart. :D:D

I'll try Keith's I think. Looks neater.

rmsharpe
May 31st, 2001, 17:18
Just don't let them get to your .htaccess/ht* files.