Login   Register  
PHP Classes
elePHPant
Icontem

File: example_html.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  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: 2010-09-01 21:41
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($file01) != '.') {
            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_gb2'.'',').' gig';
                } else {
                    
$sizer number_format($size_mb2'.'',').' mb';
                }
            } else {
                
$sizer number_format($size_kb0'.'',').' kb';
            }
        } else {
            
$sizer $bytes.' b';
        }
        return 
$sizer;
    }


?>