<?php
    function cmp ($a, $b)
    {
        return strcasecmp($a, $b);
    }

    $hHandle=opendir('.');

    $fileCount=0;
    $dirCount=0;

    $i = 0;
    $j = 0;

    $col = 1;

    $fileArr = array();
    $dirArr = array();


    while (($file = readdir($hHandle))!==false) 
    {
        if(is_dir($file)) 
        {
            if($file != '..' && $file != '.')
                $dirArr[$dirCount++] = $file;
        } 
        else 
            $fileArr[$fileCount++] = $file;
    }

    usort($fileArr, "cmp");
    usort($dirArr, "cmp");

    echo "<table border='0' width='100%'><tr><td width='50%' valign='top'><p><blockquote>";

    for(; $i < sizeof($dirArr); $i++)
    {
        echo "<font size='2'>(dir) <a target='_self' href='" . $dirArr[$i] . "'>" . $dirArr[$i] . "</a></font><br>";
        
        if((($i + $j) >= (($fileCount + $dirCount)/2)) && $col != 2)
        {
            $col = 2;
            echo "</blockquote></p></td><td width='50%' valign='top'><p>";
        }
    }

    for(; $j < sizeof($fileArr); $j++)
    {
        echo "<a target='_self' href='" . $fileArr[$j] . "'><font size='2'>" . $fileArr[$j] . "</font></a><br>";

        if((($i + $j) >= (($fileCount + $dirCount)/2)) && $col != 2)
        {
            $col = 2;
            echo "</blockquote></p></td><td width='50%' valign='top'><p>";
        }
    }


    closedir($hHandle); 

    echo "</p></td></tr></table><br><p align='center'>Totalt $dirCount katalog(er) och $fileCount fil(er)</p>"

?>