PHP Classes

File: Examples

Recommend this page to a friend!
  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: 12 years ago
Size: 2,262 bytes


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

// create the backup

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

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

// if the file is encrypted, use this

// extract it
// the password will only be used if required

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

$entry=new CFAEntry("file.txt");
fwrite($fp, "heyho!");


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

// If wished, the single Files can be extracted
$fp2=fopen("foo.txt", "w+");
while (!
feof($fp)) {
fwrite($fp2, fread($fp, 1));

// 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())