Location: PHPKode > scripts > Dir Info > dir-info/dirinfo_sample.php
<HTML>
<HEAD><TITLE>DIRINFO Class DEMO</TITLE>
</HEAD>
<BODY>
<?php

    include_once "dirinfo.php";

    //===== READ DIRECTORY INTO OBJECT
    // define icon images,
    //      left hand side= file extension or 'File Folder' or 'default'(unknown')
    //      right hand side = image location; look for /icons in Apache
    $icon = array(
                'default'=>'none.gif',
                'File Folder'=>'/icons/dir.gif',
                'html'=>'/icons/world1.gif',
                'txt' => '/icons/text.gif');
    // specify directory to be read and the url path
    $root_dir = $_SERVER['DOCUMENT_ROOT'];
    $root_url = "http://".$_SERVER['SERVER_NAME'];
    // instantiate new class with filter ("*"), icon list, and date format
    //      date format is using strftime format
    $dir = new DIRINFO($root_dir, $root_url, "*", $icon, "%d/%m/%y %H:%M");
?>

<?php
    //===== DETAIL LISTING =====================================================

    //---- Default listing
    echo "<H1>Detail Listing: Default</H1>";
    $dir->DisplayList();
    //---- Customized Listing
    echo "<HR><H1>Detail Listing: Customized</H1>";
    // Define sorting order: file type follows by file name
    $dir->Sort(array('ftype', 'Name'));
    // Define columns to display
    // built-in field: Name, Name-url, Attribute, Type, Modified, Created, Accessed
    // Left hand side: field anme
    // Right hand side: descirption to be used for header row display
    $display=array('Name-url'=>'Name',
                   "Size"=>"Size",
                 "Type"=>"Type",
                "Modified"=>"Modified"
            );
    // Display it
    $dir->DisplayList("class='dirinfo' BORDER=1", $display);
    // Display is tabulated in table
    //  we define  <TABLE class='dirinfo' BORDER=1>
    //  The header row is using <TH> enclosure:
    //        thus .dirinfo TH format the header row
    //  The icon is using IMG:    .dirinfo IMG
    //  The link is using A:     .dirinfo A
    //  Each field is using class as its own name, thus:
    //          .dirinfo .Name-url
    //          .dirinfo .Size
    //          .dirinfo .Type
    //          .dirinfo .Modified
?>
<style>
.dirinfo { font: 12pt; font-weight: bold; width: 100%; text-align:center;
            border: none; }
.dirinfo IMG  {  border:none; height: 15px;}
.dirinfo TH { font: 12pt; background: gray; font-weight: bold;
            border: outset 5}
.dirinfo A { font: 12pt; font-weight: bold;
            height: 15px; border:none; padding: 2px; text-decoration: none}
.dirinfo A:HOVER { background: cyan}
.dirinfo .Name-url { font: 12pt; font-weight: bold; height: 15px;
            width: 30px;
            background: lightyellow;
            text-align:left; padding: 2px; text-decoration: none}
.dirinfo .Size { height: 15px; font:italic
            width: 100px; text-align: right;
            background: lightgreen;
            padding: 2px; text-decoration: none}
.dirinfo .Type { background: yellow}
.dirinfo .Modified { background: darkgreen}
?>

</style>
<?php
    //===== ICON DISPLAY =======================================================
    echo "<HR><H1>ICON Display</H1>";
    // Define sorting order: file type follows by file name
    $dir->Sort(array('ftype', 'Name'));
    // define field to be display
    $display=array('icon'=>'Name',
                   "Size"=>"Size",
                 "Type"=>"Type",
                "Modified"=>"Modified"
            );
    // display it
    $dir->DisplayIcon("class='diricon' BORDER=1 WIDTH=80%", 4, $display);

?>
<style>
.diricon { font: 12pt; font-weight: bold; width: 100%; text-align:center;
            border: none; }
.diricon IMG  { border: none; height: 50px; text-align:center }
.diricon A { font: 12pt; font-weight: bold;
            height: 15px; border:none; padding: 2px; text-decoration: none}
.diricon A:HOVER { background: cyan}

.diricon SPAN.icon { font: 12pt; font-weight: bold; height: 30px;
            width: 50px; text-align: center;
            background: lightblue;
            padding: 2px; text-decoration: none}
.diricon SPAN.Size { height: 15px; font:italic
            width: 100px; text-align:center;
            background: lightgreen;
            padding: 2px; text-decoration: none}
.diricon SPAN.Type { font: 8pt italic; background: lightgreen;}
.diricon SPAN.Modified { font: 8pt italic; background: lightyellow;}
</style>

<?php
    //===== ICON DISPLAY =======================================================
    echo "<HR><H1>Custom Field</H1>";
    // create a field 'mylink'
    for ( $i = 0; $i < $dir->no_item; $i ++)
    {   switch ( $dir->stat[$i]['Type'])
        {   case 'File Folder':
                $dir->stat[$i]['mylink'] = "Directory: ".
                        $dir->stat[$i]['fname'];
                break;
            default:
                $dir->stat[$i]['mylink'] = $dir->stat[$i]['Name-url'];
                break;
        }
    }

    $display=array(
            'mylink'=>'My Transform',
            "Size"=>"Size",
            "Type"=>"Type",
            "Modified"=>"Modified"
            );
    // Display it
    $dir->DisplayList("class='dirinfo' BORDER=1", $display);
?>
<style>
.dirinfo .mylink { font: 8pt italic; background: lightyellow;}
</style


</BODY>
</HTML>

Return current item: Dir Info