is_dir() function problem
Posted: Wed Mar 03, 2004 9:35 am
Hey I am extremely new to PHP and I have never studied any other programming languages. So I feel like a huge dork. But I figure I will get better someday. Anyway here is my problem. I am trying to list all subfolders that exist under a certain folder in my site and filter out files. When I try to use is_dir($myDir) I cannot capture any directories. Maybe I need to fix something in my php configuration. I'm not sure. I'm not even sure if I am asking the correct question.
here is my code so far...
$rootDir = $_SERVER[DOCUMENT_ROOT];
$ncicDir = $rootDir . "/newcreationinchrist.com";
//open ncic directory and display it's contents
if($handle = opendir($ncicDir)){
echo "<br><br><b>Site Subdirectories: </b>";
while (false !== ($file = readdir($handle))){
if($file != "." && $file != ".."){
//capture only folders
if(is_dir($file)){
$folderName = $file . "Dir";
$folderName = str_replace(" ","_", $folderName);
$fixURL = str_replace(" ", "%20", $file);
$folderURL = $ncicDir ."/" .$fixURL;
echo "<br><br>$tab<a href=$folderURL><b>" . $folderName . "</b></a>";
}
}
}
closedir($handle);
}else{
echo "<br><br>--- error opening <b>$ncicDir</b> directory ---";
}
also I would like to extend this to loop through and list all subfolders of the subfolders of the ncicDir.
Thanks for any you help you guys might have.
here is my code so far...
$rootDir = $_SERVER[DOCUMENT_ROOT];
$ncicDir = $rootDir . "/newcreationinchrist.com";
//open ncic directory and display it's contents
if($handle = opendir($ncicDir)){
echo "<br><br><b>Site Subdirectories: </b>";
while (false !== ($file = readdir($handle))){
if($file != "." && $file != ".."){
//capture only folders
if(is_dir($file)){
$folderName = $file . "Dir";
$folderName = str_replace(" ","_", $folderName);
$fixURL = str_replace(" ", "%20", $file);
$folderURL = $ncicDir ."/" .$fixURL;
echo "<br><br>$tab<a href=$folderURL><b>" . $folderName . "</b></a>";
}
}
}
closedir($handle);
}else{
echo "<br><br>--- error opening <b>$ncicDir</b> directory ---";
}
also I would like to extend this to loop through and list all subfolders of the subfolders of the ncicDir.
Thanks for any you help you guys might have.