<?php   ### readdir_spaltenarray.php ###


$path = "c:/programme/xampp";

#------------------------------------------------------------------------------
# Verzeichnislisting Datenarray erstellen 
#------------------------------------------------------------------------------
function get_file_list($path)
{
    $path = rtrim($path,'/');

    if($dh = opendir($path))
    {
        $_dir = array();
        $_dir['name'] = array();
        $_dir['type'] = array();
        $_dir['size'] = array();
        $_key = 0;

        while(false !== ($filename = readdir($dh)))
        {
            $key++;
            $_dir['name'][$key] = $filename;


            if (is_file($path.'/'.$filename))
            {
                $_dir['type'][$key] = 'file';
                $_dir['size'][$key] = filesize($path.'/'.$filename);
            }
            elseif(is_dir($path.'/'.$filename))
            {
                $_dir['type'][$key] = 'dir';
#                $_dir['size'][$key] = '';                  
            }
        }
        closedir($dh);
    }

    return $_dir;
}    

#------------------------------------------------------------------------------
# Verzeichnislisting HTML-String erzeugen
#------------------------------------------------------------------------------
function make_file_list($_dir)
{
    if (!is_array($_dir)) { return false; }
    
    $html  = "    <table class=\"dirlist\">\r\n";
    
    foreach($_dir['name'] as $key => $name)
    {
        $html .= "        <tr>\r\n";
        $html .= "            <td>".htmlspecialchars($name)."</td>\r\n";
        $html .= "            <td>".htmlspecialchars($_dir['type'][$key])."</td>\r\n";
        $html .= "            <td>"
              .(isset($_dir['size'][$key])?htmlspecialchars($_dir['size'][$key]):'')
              ."</td>\r\n";        
        $html .= "        </tr>\r\n";
    }
    
    $html .= "    <table>\r\n";    

    return $html;
}
    
#==============================================================================
# php main
#==============================================================================

$_dir = get_file_list($path);

echo "<pre>\r\n";
echo htmlspecialchars(print_r($_dir,1));
echo "</pre>\r\n";

echo make_file_list($_dir);


?>