homepage Welcome to WebmasterWorld Guest from 54.81.170.186
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Php List Directory
Guberten




msg:1285380
 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

<?php
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>";
}
}
closedir($dh);
}

getDirContents("/");

?>

Thanks

 

avyworld




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

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) {
$dir=opendir($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! :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved