PHP Classes

File: example1.php

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


Class file image Download

 * this example would list all the image files
 * found in /home/user/public_html
 * which do not also exist in /var/www/html
 * and copy over the missing files

// ----------- initialise ------------

$dest='/var/www/html'; // NB class wil sort out trailing dir seperators

$t=new pfpFileTree($src);

$t->ignoreNoDescend=true; // ignore some errors
$t->caseSensitive=false; // used for globbing only

// --------- grab images -----------
// note it would have been much more efficient to...
// $t->readTree(array('name'=>'{*jpg,*.png,*.gif}');

// $t->data is now populated with a list of all image files


// --------- compare with dest ---------
$files=$t->filter(array('cmp'=>2)); // just find the missing files

if ($t->writeTo($dest)===false) {
"Copy would have failed for: ";
} else {
"files copied";