Login   Register  
PHP Classes
elePHPant
Icontem

File: example2.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Colin McKinnon  >  pfpFileTree  >  example2.php  >  Download  
File: example2.php
Role: Example script
Content type: text/plain
Description: example
Class: pfpFileTree
Manipulates files in directories recursively
Author: By
Last change:
Date: 3 years ago
Size: 1,080 bytes
 

Contents

Class file image Download
<?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);