Examples

On this page are some basic examples using Zippr. Important! Make sure that Zippr has write permission in the new zip file's / unzip target directory. Alse make sure the files you want to zip are readdable by the script!


Extract archive

For extracting an archvive you don't have to create a new instance of Zippr. Extracting can be done using the static method extractArchive.

<?php
// Location for zip archive
$location = 'uploads/archive.zip';

// Target directory to extract to. The script needs write permission for this directory!
$target = '/some/directory/target';

Zippr::extractArchive($archive, $target);
?>

Creating archive and adding files

For creating an archive you need to create a new instance of Zippr. Adding files and directories can be done using the addFile and addDir methods.

<?php
// Path for new archive
$archive = 'files/download.zip';

$Zippr = new Zippr($archive);

// Adding a directory
$Zippr->addDir('path/to/dir');

// Add a file to target directory 'foo' in the archive
$Zippr->addFile('public/robots.txt', 'foo');

// Zippr saves the archive autmatically in the __destruct method
unset($Zippr);
?>
Fork me on GitHub