homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

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

10+ Year Member

Msg#: 405 posted 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>";






10+ Year Member

Msg#: 405 posted 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) {

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.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved