Location: PHPKode > scripts > pfpFileTree > example3.php
<?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));
}


Return current item: pfpFileTree