<?php
 
 
/**
 
 * @author Jamie Curnow
 
 * This is an example of the Stats class working on all files in the specified directory.
 
 * This example is meant to be run from a browser.
 
 */
 
 
    require_once('file_stats.class.php');
 
    $file_stats = new File_Stats();
 
 
    // Change this directory to wherever you have large files.
 
    $directory = '.';
 
 
    print '<table border="1" cellspacing="0" cellpadding="4">';
 
    print '<tr><th>Type</th><th>Filename</th><th>File Size</th><th>Modified Time</th></tr>'."\n";
 
    // Loop over all items in this Directory
 
    $directory_handle = @opendir($directory);
 
    while (false !== ($file = @readdir($directory_handle))) {
 
        // skip anything that starts with a '.' i.e.:('.', '..', or any hidden file)
 
        if (substr($file, 0, 1) != '.') {
 
            if ($file_stats->getFileType($directory.'/'.$file) == File_Stats::TYPE_DIR) {
 
                // This is a Directory
 
                print '<tr><td>Dir></td>'.$file.'</td><td> </td><td>'.date('Y-m-d g:ia', $file_stats->getFileModifiedTime($directory.'/'.$file)).'</td></tr>'."\n";
 
            } else {
 
                // This is a File
 
                print '<tr><td>File</td><td>'.$file.'</td><td>'.getReadableSize($file_stats->getFileSize($directory.'/'.$file)).'</td><td>'.date('Y-m-d g:ia', $file_stats->getFileModifiedTime($directory.'/'.$file)).'</td></tr>'."\n";
 
            }
 
        }
 
    }
 
    print '</table>';
 
 
 
    function getReadableSize($bytes) {
 
        if ($bytes >= 1024) {
 
            $size_kb = round(($bytes / 1024),0);
 
            if ($size_kb >= 1024) {
 
                $size_mb = round(($bytes / 1024 / 1024),2);
 
                if ($size_mb >= 1024) {
 
                    $size_gb = round(($bytes / 1024 / 1024 / 1024),2);
 
                    $sizer = number_format($size_gb, 2, '.', ',').' gig';
 
                } else {
 
                    $sizer = number_format($size_mb, 2, '.', ',').' mb';
 
                }
 
            } else {
 
                $sizer = number_format($size_kb, 0, '.', ',').' kb';
 
            }
 
        } else {
 
            $sizer = $bytes.' b';
 
        }
 
        return $sizer;
 
    }
 
 
 
?>
 
 |