PHP Classes

File: example3.php

Recommend this page to a friend!
  Classes of Colin McKinnon   pfpFileTree   example3.php   Download  
File: example3.php
Role: Example script
Content type: text/plain
Description: example
Class: pfpFileTree
Manipulates files in directories recursively
Author: By
Last change:
Date: 13 years ago
Size: 1,191 bytes
 

Contents

Class file image Download
<?php
/**
 * examples 3
 *
 * using the callback function to add a new file attribute
 */

// ----------- initialise ------------
require_once('pfpFileTree.inc.php');

$src='/var/www/html';

$t=new pfpFileTree($src);

$t->addCallBack('dummyCallBack');
$t->addCallBack('getMimeType'); // NB we can add multiple callbacks
$t->delCallBack('dummyCallBack'); // ... and remove them

$t->readTree(array('size'=>'>10000','mimetype'=>'!text/html'));

$t->ls();

function
getMimeType($file)
{
    global
$t;
   
$attribute='mimetype';
   
// note that if we want to manipulate $t->data here
    // $file is a canonical path - but we need the path
    // relative to the baseDir to find the right array
    // entry...
   
$effPath = substr($file, strlen($t->baseDir));
    if (@
array_key_exists($attribute, $t->data[$effPath])) {
       
// already populated - return the current value
       
return array($attribute=>$t->data[$effPath][$attribute]);
    } else {
       
// NB mime_content_type() is deprecated
       
return array($attribute=>mime_content_type($file));
    }
}

function
dummyCallBack($file)
{
    print
"this code is never called";
   
// but the following would be valid...
   
return array('dummy'=>true, 'backwards'=>strrev($file));
}