Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

how to zip a folder using php

<?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 by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #zip #folder #php
ADD COMMENT
Topic
Name
1+9 =