เราสามารถใช้คลาส PHP ZipArchive เพื่อทำการซิปและคลายซิปโฟลเดอร์ใน PHP ตั้งแต่ PHP 5.3 คลาสนี้ถูกสร้างขึ้นมา สำหรับการใช้งานใน windows ผู้ใช้จำเป็นต้องเปิดใช้งาน php_zip.dll ภายใน php.ini
ตัวอย่าง
<?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();
}
?>