PHP Classes

File: example_html.php

Recommend this page to a friend!
  Classes of Jamie Curnow   32bit File Stats   example_html.php   Download  
File: example_html.php
Role: Example script
Content type: text/plain
Description: Example with HTML output
Class: 32bit File Stats
Get information of large files on 32 bit systems
Author: By
Last change:
Date: 14 years ago
Size: 2,196 bytes
 

Contents

Class file image Download
<?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>&nbsp;</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;
    }


?>