Reputation: 713
Newb here
I'm attempting to craft a simple function that will create a simple list of all the subdirectories available within a directory.
My code currently returns all the names of the subdirectories but it also returns all the names of the files in the directory which i do not want.
function getDirectories(){
echo "Directories available:<br />";
foreach (glob("*") as $dirname ) {
echo "<a target=\"_blank\" href=\"$dirname \">$dirname</a><br />";}
}
Upvotes: 0
Views: 73
Reputation: 6224
Use glob
function with GLOB_ONLYDIR
flag.
glob('*', GLOB_ONLYDIR);
Upvotes: 1
Reputation: 49949
Look over here: http://www.php.net/manual/en/function.is-dir.php
if( is_dir( $dirname ) ) {
// Do stuff
}
Upvotes: 1