Creating a new zip file in ZipArchive.
Creating a new zip file in ZipArchive.Creating a new Zip file in ZipArchive
For creating zip file, use zipArchive () class. Create a new zip file in ZipArchive. Use the conditional statement to add a file in the ZipArcive class. If the file exists, the create() function will generate a new zip file, in case of failure, it will print failed in creating zip file.
<?php
$newzip = new ZipArchive;
$create = $zip->open(’file.zip’, ZipArchive::CREATE);
if ($create=== TRUE) {
$newzip->addFile(’file.txt’,'file.txt');
$newzip->close();
echo "Zip file successfully created";
} else {
echo "Failed in creating zip file";
}
?>