Using the PHP zip function without exec
Because the exec function cannot be run on our servers, here is an example of how to work with zip files within PHP without having to call the operating system's unzip and zip functions via exec. Save this code as testzip.php in, for example, the public_html directory.
<?
echo 'Test aanmaken zipfile';
$zip = new ZipArchive();
$filename = "./test.zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
exit("Cannot open <$filename>, do you have write permission?\n");
}
$zip->addFile("./testzip.php","/testzip.php");
echo "Aantal bestanden in de zipfile: " . $zip->numFiles . "\n";
echo "De status:" . $zip->status . "\n";
$zip->close();
?>
