<?php
$dir = "./";
if(!($fd = opendir($dir)))
  exit("Nie mogę otworzyć katalogu $dir!");

$katalogi = array();
$pliki = array();

while (($file = readdir($fd)) !== false){
  if($file != '.' && $file != '..'){
    if(is_file($dir.$file)){
      $pliki[] = $file;
    }
    else if(is_dir($dir.$file)){
      $katalogi[] = $file;
    }
  }
}

sort($pliki);
sort($katalogi);

echo "<strong>Katalogi</strong><br />\n";

foreach($katalogi as $name){
  echo "$name <br />\n";
}

echo "<br \><strong>Pliki</strong><br />\n";

foreach($pliki as $name){
  echo "$name <br />\n";
}

closedir($fd);
?>

