I added a line 9: if (is_dir($file)) to select only the folders, but it only adds the '.' and '..' folders if I take line 10 out. Also, I thought of using 'filetype' but was not sure on how to only get the dir part out of it.
Can someone help and explain why it does not add other folders? or is there any other way select only the folders?
here is the code:
Code: Select all
<?php
clearstatcache();
$path = "/exports/active/projects/Virtual Bulletin Board/test folder/";
$folders_matched = array();
if (is_dir($path)) {
if ($dh = opendir($path)) {
while(($file = readdir($dh)) !== false) {
//if (is_dir($file)){ //will only give me . and .. as dirs but not the rest of the folders
if (strcmp($file, '.')==0 || strcmp($file, '..')==0) continue;
echo "filename: $file : filetype: " . filetype($path . $file) . "<br>";
array_push($folders_matched, $file);
//} // uncomment this }
}// end while
} // end if
closedir($dh);
}// end if
sort($folders_matched);
reset($folders_matched);
print'<pre>' . print_r($folders_matched, TRUE) . '</pre>';
?>