PDA

View Full Version : php: getting list of directories?


seeFresh
11-02-2005, 08:59 PM
Hi, I'm new to php, but experienced programmer. Was big into perl for a while, but now I'm doing asp.net. My new client needs a flash program that gets some info from the server, liiiike, current files available and such. I need to return to flash a list of the directories then a list of the files in a subdirectory chosen. Here is the script I've got so far:


<?php>
$dir = "/";
$response = "dirs=";

if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if(is_dir($file)) {
$response += "||$file";
}
closedir($dh);
}
} else {
echo "Not a Dir";
}
echo $response;
?>


What do I put in the $dir variable to get the list of subdirectories in the same folder as my script? I need it to be universal so that it will work no matter what directory I put this script in.

Any help is GREATLY appreciated!

thanks,

Chris
http://www.seefresh.net

Xeef
11-02-2005, 11:40 PM
try :

$dir = getcwd ()."/"; (not usre abouth the "/" )

[Sx]
11-06-2005, 09:45 AM
getcwd() would be quite enough