<?php
$zipFile = "tmp/data.zip";
//prepare the archive to be unpacked
if (!is_dir("tmp")) {
mkdir("tmp");
}
$source = new ZipArchive();
$source->open($zipFile,
ZipArchive::CREATE | ZipArchive::OVERWRITE);
$source->addFromString("file.txt", "Hello, world!\n");
$source->close();
$zip = new ZipArchive;
$res = $zip->open($zipFile);
if ($res === TRUE) {
$zip->extractTo('tmp/');
$zip->close();
} else {
throw new Exception("Could not open archive");
}