Php Zip Files On The Server In A Directory

[Solved] Php Zip Files On The Server In A Directory | Php - Code Explorer | yomemimo.com
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

Answers related to php zip files on the server in a directory

Code Explorer Popular Question For Php