<?php
/**
* example2.php
*
* create tarball of all files modified in the last week
* and download via HTTP
*/
// ----------- initialise ------------
require_once('pfpFileTree.inc.php');
$src='/var/www/html/';
$t=new pfpFileTree($src);
$t->ignoreNoDescend=true;
$t->caseSensitive=false;
$since='>' . (time() - 7*24*60*60);
// ---------- grab files --------
$flist=$t->readTree(array('mtime'=>$since, 'type'=>'f','r'=>true));
// NB excluding directories and only selecting readable files
if (!count($flist)) {
print "No new files or files unreadable\n";
print $t->error;
exit;
}
$templist=tempnam(sys_get_temp_dir(), 'flst');
$outputfile=tempnam(sys_get_temp_dir(), 'wtgz');
chdir($src);
if ($templist && $outputfile
&& file_put_contents($templist,implode("\n",array_keys($flist)))) {
`tar -T $templist -czf $outputfile`;
header('Content-Type: application/x-compressed');
header('Content-Disposition: attachment; filename="modified.tgz"');
readfile($outputfile);
} else {
print "Error $templist $outputfile";
}
@unlink($templist);
@unlink($outputfile);
|