<?php
 
 
// include API class:
 
include ("phptempt.php");
 
 
function listfolder ($dirpath)
 
{
 
    global $t;
 
    global $con;
 
 
    static $count = 0; // debug
 
 
    // begin block:
 
    $t->begin ("dirlist");
 
 
    // add value to a placeholer in the block:
 
    $t->addVal ("FOLDERNAME", $dirpath);
 
 
    // open folder; if an error occurres on attempt to open folder,
 
    // then issue a message:
 
    //
 
    $dir = @opendir ($dirpath);
 
//    echo "dir==$dir<br>"; // debug
 
    if (is_bool($dir) && !$dir) {
 
        $t->begin ("entry");
 
        $t->addVal ("NOACCESS", ++$count);
 
        $t->end ("entry");
 
    }
 
 
    // otherwise, print contents of folder:
 
    //
 
    else {
 
 
        while ($file = readdir ($dir)) {
 
 
            // ignore . and .. entries:
 
            if ($file=="." || $file=="..")
 
                continue;
 
 
            $filepath = "$dirpath/$file";
 
 
            $t->begin ("entry");
 
 
            if (is_dir($filepath)) {
 
                // recursively list subfolder:
 
                listfolder ($filepath);
 
            }
 
            else if (is_file($filepath)) {
 
                // print textfile:
 
                $t->begin ("textfile");
 
                $t->addVal ("NAME", $file);
 
                $t->end ("textfile");
 
            }
 
 
            $t->end ("entry");
 
        }
 
 
        $dir = closedir ($dir);
 
    }
 
 
    // close block, ready for next iteration:
 
    $t->end ("dirlist");
 
}
 
 
 
/****************************
 
* Main script starts here
 
*****************************/
 
 
// include precompiled template:
 
$t = new phptempt ("list_dir.inc");
 
 
// check URL parameter:
 
if (!isset ($rootfolder))
 
{
 
    print "Please provide parameter 'rootfolder'";
 
    exit;
 
}
 
 
// add to template variable:
 
$t->addVal ("FOLDERNAME", $rootfolder);
 
 
// recursively print contents of project root directory:
 
listfolder ($rootfolder);
 
 
// output template:
 
$t->out();
 
 
?>
 
 |