When you get a directory listing for a folder, it will include the folder "." and "..", dont forget to filter those out if you dont want them. Check which items are files and which ones are folders by using the isdir() and isfile() functions like:
$handle = opendir("/directory/");
$i=0;
// the while loop and sort are just nice
// to have, to get the results in
// alphabetic order
while(($object = readdir($handle))!=false) {
$items[$i] = $object;
$i++;
}
sort($items);
foreach($items as $object) {
if(isdir($object)) print "directory $object";
if(isfile($object)) print "file $object";
}
closedir($handle);