PHP-এ ফোল্ডারটি জিপ এবং আনজিপ করার জন্য আমরা PHP ZipArchive ক্লাস ব্যবহার করতে পারি। PHP 5.3 অনুযায়ী, এই ক্লাসটি অন্তর্নির্মিত। উইন্ডোজে ব্যবহারের জন্য ব্যবহারকারীদের php.ini এর ভিতরে php_zip.dll সক্ষম করতে হবে।
উদাহরণ
<?php
//Enter the name of directory
$pathdir = "Directory Name/";
//Enter the name to creating zipped directory
$zipcreated = "test.zip";
//Create new zip class
$newzip = new ZipArchive;
if($newzip -> open($zipcreated, ZipArchive::CREATE ) === TRUE) {
$dir = opendir($pathdir);
while($file = readdir($dir)) {
if(is_file($pathdir.$file)) {
$newzip -> addFile($pathdir.$file, $file);
}
}
$newzip ->close();
}
?>