<?

//
// Copyright (C) 2002   Robert Nowotniak <robercik@toya.net.pl>
//

ini_set('display_errors''1');
ini_set('track_errors''1');
ini_set('log_errors''0');

function 
ls($plik)
{
    echo 
"<PRE>";

    if ((
$h = @opendir($plik))) {
        while (
false !== ($entry readdir($h))) {
            
$st = @lstat($plik '/' $entry);
            if (! 
$st) {
                
printf("%50s     %s\n"$entry$php_errormsg);
                continue;
            }

                if (
$st[2] & 0010000$modebuf 'p';
            elseif (
$st[2] & 0020000$modebuf 'c';
            elseif (
$st[2] & 0040000$modebuf 'd';
            elseif (
$st[2] & 0060000$modebuf 'b';
            elseif (
$st[2] & 0100000$modebuf '-';
            elseif (
$st[2] & 0120000$modebuf 'l';
            elseif (
$st[2] & 0140000$modebuf 's';
            else 
$modebuf '?';

            
$modebuf substr_replace($modebuf$st[2] & 00400 'r' '-'11);
            
$modebuf substr_replace($modebuf$st[2] & 00200 'w' '-'21);
            
$modebuf substr_replace($modebuf$st[2] & 00100 'x' '-'31);
            
$modebuf substr_replace($modebuf$st[2] & 00040 'r' '-'41);
            
$modebuf substr_replace($modebuf$st[2] & 00020 'w' '-'51);
            
$modebuf substr_replace($modebuf$st[2] & 00010 'x' '-'61);
            
$modebuf substr_replace($modebuf$st[2] & 00004 'r' '-'71);
            
$modebuf substr_replace($modebuf$st[2] & 00002 'w' '-'81);
            
$modebuf substr_replace($modebuf$st[2] & 00001 'x' '-'91);

            if (
$st[2] & 004000)
                
$modebuf substr_replace($modebuf$st[2] & 00100 's' 'S'31);
            if (
$st[2] & 002000)
                
$modebuf substr_replace($modebuf$st[2] & 00010 's' 'S'61);
            if (
$st[2] & 001000)
                
$modebuf substr_replace($modebuf$st[2] & 00001 't' 'T'91);

            
$czas strftime("%Y-%m-%d %H:%M"$st[10]);

            
printf("%7s %2d %5d %5d %9d %16s "$modebuf$st[3], $st[4], $st[5], $st[7], $czas);
            if (
is_dir($plik '/' $entry)) {
                echo 
"<A HREF=\"" .basename($_SERVER['PHP_SELF']). "?f=$plik/" htmlspecialchars($entry) . "\">";
                echo 
htmlspecialchars($entry);
                echo 
"</A>";
            } else
                echo 
htmlspecialchars($entry);
            
printf("\n");
        }
        
closedir($h);
    } else
        echo 
"Nie można wylistować $plik ($php_errormsg)\n";

    echo 
"</PRE>";
}

if (! isset(
$_GET['f']))
    
ls(".");
else
    
ls($_GET['f']);

?>