PHP code contains comments for explanation:
PHP Code:
<?php
$zipname = "archive.zip"; // Name of the archive
$file1 = "a-file"; // The file that will be inserted into archive (must exist on the server)
$file1new = "nuw-filename"; // The new name of the file in the archive
$zip = new ZipArchive(); // Class for creating a new ZIP archive
if($zip->open($zipname, ZIPARCHIVE::CREATE)!==TRUE) {
die("Error");
}
$zip->addFile($file1, $file1new);
$countfiles = $zip->numFiles; // The total number of files
$status = $zip->status;
if($status == 0) { print "The archive was created successfullyTotal number of files: " . $countfiles . "---"; }
else { die("Error creating archive"); }
$zip-close();
?>
The class ZipArchive() required ZZIPlib
ZIPARCHIVE:: CREATE - create archive.