Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Php List Directory



12:47 am on Apr 5, 2002 (gmt 0)

Ok I need to know how to list the directory in the root with php, where everything is that same as if I were browsing through ftp(without the graphics)
This is what I have so far, but it doesn't display them in directories, how do I display it in the directories, and allowing me to click on the directory to go the next directory. Thats not a must, but I need to have each directory listing and not all the files at one time like this one does

function getDirContents($slashdir) {
$dh = opendir($slashdir);

while (($file = readdir ($dh))) {
if (is_dir($slashdir . $file) && $file != "." && $file != "..") {
getDirContents ($slashdir . $file . "/");
} else if ($file != "." && $file != "..") {
echo $file . "<br>";





12:54 pm on Apr 13, 2002 (gmt 0)

10+ Year Member

I don't understand what you are asking for. If you are talking about just displaying directories and images in a directory, then you could just make a link for each directory and it opens up the same page with the QueryString having a variable containing the path to look in. Making any sense? Here's some sample code you could use:

function getDir($dirName) {

while(($curr=readdir($dir))!=null && $curr!="." && $curr!="..") {
if(is_dir($curr)) {
print("<a href=\"/getdir.php?dir=$dirName"."$curr\">$curr</a>\n<br />");
elseif(is_file($curr)) {
print("$dirName"."$curr\n<br />");
} getDir(($newdir)?"$newdir":"/");

Hope that helps!

Happy coding! :)


Featured Threads

Hot Threads This Week

Hot Threads This Month