Examples

Examples – Some simple usage examples

Extract a tar archive to a sub directory

Here we simply take a tar archive called archive.tar and extract its contents to the folder

<?php
require_once "File/Archive.php";

File_Archive::extract('archive.tar/''output');
?>

Send a zip archive containing the content of a tar file to the standard output

<?php
require_once "File/Archive.php";

File_Archive::extract(
    
//The content of archive.tar appears in the root folder (default argument)
    
'archive.tar/',

    
//And is written to ...
    
File_Archive::toArchive(       // ... a zip archive
        
'archive.zip',             // called archive.zip
        
File_Archive::toOutput()   // that will be sent to the standard output
    
)
);
?>

Extracting a file from an archive

Use extract() to get files out of an archive. When specifying the file to extract, make sure to use the archive name as first folder.

<?php
require_once "File/Archive.php";

File_Archive::extract(
    
'archive.tar/inner.tgz/file.txt',
    
File_Archive::toOutput()
);
?>