PHP Classes

File: file_list.php

Recommend this page to a friend!
  Classes of Roger George   PHP Web Site Compare Files   file_list.php   Download  
File: file_list.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: PHP Web Site Compare Files
Compare the list of files of two Web sites
Author: By
Last change: Update of file_list.php
Date: 1 year ago
Size: 1,571 bytes
 

Contents

Class file image Download
<?php
//Prevent page caching
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

//Gets list of file paths in all folders except for ignored folders.
function globRecursive($pattern){
   
$files = Array();
   
$files = glob($pattern, 0);
    foreach (
glob(dirname($pattern).'/*', GLOB_ONLYDIR) as $dir){
       
$fileok = true;
        if (
$fileok == true){
           
$files = array_merge($files, globRecursive($dir.'/'.basename($pattern), 0));
        }
    }
    return
$files;
}

//Convert bytes to friendly size description.
function humanFileSize($bytes, $decimals = 0){
   
$sz = 'BKMGTP';
   
$factor = floor((strlen($bytes) - 1) / 3);
    return
sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)).' '.@$sz[$factor];
}

/*Create array $details:
    [#]["filename"] = filename
    [#]["date"] = modified date
    [#]["size"] = size in bytes
    [#]["old"] = 1 if older than 7 days and 0 if not */
$files = globRecursive("*");
$details = Array();
$aCount = -1;
for(
$i = 0; $i < count($files);$i++){
   
$aCount++;
   
$details[$aCount]['filename'] = str_replace('../../', '', $files[$i]);
   
$details[$aCount]['date'] = date ('F d Y (H:i:s)', filemtime($files[$i]));
   
$details[$aCount]['size'] = humanFileSize(filesize($files[$i]));
    if (
filemtime($files[$i]) < (time() - (7 * 24 * 60 * 60 ))){
       
$details[$aCount]['old'] = '1'; //Older than 7 days
   
} else {
       
$details[$aCount]['old'] = '0';
    }
}

//Draws a JSON string of the $details array.
echo json_encode($details);
?>