Login   Register  
PHP Classes
elePHPant
Icontem

File: Examples

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Tobias Marstaller  >  CFA Library  >  Examples  >  Download  
File: Examples
Role: Example script
Content type: text/plain
Description: Example code and a short documentation for all 4 classes.
Class: CFA Library
Compress and extract files from a single file
Author: By
Last change:
Date: 2011-08-06 13:59
Size: 2,262 bytes
 

Contents

Class file image Download
<?php
// Create a CFA File from a Directory
$creator=new CFACreator("dir/to/create/from");
// if you want to encrypt, use this
$creator->setPassword("foobar");

// create the backup
$creator->packTo("archieve.cfa");

// if you want to encrypt, pass a true to packTo()
$creator->packTo("archieve.blowfish.cfa"true);


// Extract a CFA File
$extractor=new CFAExtractor("archieve.cfa");

// if the file is encrypted, use this
$extractor->setPassword("foobar");

// extract it
// the password will only be used if required
$extracor->extractTo("dir/to/extract/to");


// Create a CFA File manually by not using Files
$file=new CFAFile("archieve.cfa");

$entry=new CFAEntry("file.txt");
$fp=$entry->getFileHandle();
fwrite($fp"heyho!");
$file->add($entry);

$file->flushToFile();

// And the oher way around, look up single entrys from an archieve
$file=new CFAFile("archieve.cfa");
$files=$file->getFileList();
foreach (
$files as $entry) {
    echo 
$entry->getName()." - ".$entry->getSize()." Bytes<br>";
}

// If wished, the single Files can be extracted
$fp=$entry->getHandle();
$fp2=fopen("foo.txt""w+");
while (!
feof($fp)) {
    
fwrite($fp2fread($fp1));
}
fclose($fp);
fclose($fp2);

// Here is a short Documentation:
?>
Class CFACreator:
    -> Constructor ( String $sourcepath )
    -> void setPassword ( String $password )
    -> void packTo ( String $filename [, boolean $encrypt=false] )

Class CFAExtractor:
    -> Constructor ( String $archieve_path )
    -> void setPassword ( String $password )
    -> void extractTo ( String $extraction_path )

Class CFAFile
    -> Constructor ( String $archieve_path [, String $password=null] )
    -> CFAEntry[] getFileList ()
    -> void remove ( CFAEntry $entry )
    -> void add ( CFAEntry $entry )
    -> void flushToFile ()
    
Class CFAEntry
    -> Constructor ( String $name )
        Note: The Name has not to be a file path, just not empty
    -> int getSize ()
    -> String getName ()
    -> String getSourcefile ()
        Note: Returns the name of the archieve this entry is contained in
              if this entry was returned from getFileList(), otherwise null
    -> FileHandle getFileHandle ()
        Note: To be used with the f* functions (e.g. fread(), fwrite())