<?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>";

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

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

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

  closedir($fd);
?>

