Question : how to zip a folder using php
Answered by : different-dunlin-twhiwxkm17md
<?php
// Enter the name of directory
$pathdir = "Directory Name/";
// Enter the name to creating zipped directory
$zipcreated = "Name of Zip.zip";
// Create new zip class
$zip = new ZipArchive;
if($zip -> open($zipcreated, ZipArchive::CREATE ) === TRUE) {
// Store the path into the variable
$dir = opendir($pathdir);
while($file = readdir($dir)) {
if(is_file($pathdir.$file)) {
$zip -> addFile($pathdir.$file, $file);
}
}
$zip ->close();
}
?>
Source : https://www.geeksforgeeks.org/how-to-zip-a-directory-in-php/ | Last Update : Mon, 27 Jun 22