Top 5 Free Dynamic ZIP Generation Libraries in PHP

Today, We want to share with you Top 5 Free Dynamic ZIP Generation Libraries in PHP.In this post we will show you generate ZIP file in php code, hear for Best of PHP scripts for generating ZIP files we will give you demo and example for implement.In this post, we will learn about Top 5 : Best open source ZIP generation libraries for PHP with an example.

Top 5 Free Dynamic ZIP Generation Libraries in PHP

There are the Following The simple About Top 5 Free Dynamic ZIP Generation Libraries in PHP Full Information With Example and source code.

As I will cover this Post with live Working example to develop php ziparchive download, so the some major generate ZIP file in php code for this example is following below.

Read Also:  how to get last inserted id in laravel 6


Create Zip File After Upload Using PHP

<form method="post" action="create_zip.php" enctype="multipart/form-data">
 <input type="file" name='file'>
 <input type="submit" name="upload_file">


 move_uploaded_file($_FILES["file"]["tmp_name"], "$folder".$_FILES["file"]["name"]);

 $zip = new ZipArchive(); // Load zip library 
 $zip_name =""; // Zip name
 if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE)
  echo "Sorry ZIP creation failed at this time";

2. PHP Zip File Functions

$zip = zip_open("");

if ($zip)
  while ($zip_entry = zip_read($zip))
    echo "<p>";
    echo "zip Name: " . zip_entry_name($zip_entry) . "<br />";
    echo "Compressed Size: "
    . zip_entry_compressedsize($zip_entry);
    echo "</p>";

Note : Full Examples –

Read Also:  Laravel 5/6/7 Import & Export data to Excel CSV using maatwebsite

3. Create a Zip archive

using main PHP libs :


$zip = new ZipArchive();
$filename = "./";

if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
    exit("cannot open <$filename>\n");

$zip->addFromString("productfilephp.txt" . time(), "#1  php create zip file from directory as productfilephp.txt.\n");
$zip->addFromString("productfilephp2.txt" . time(), "#2  php create zip file from directory productfilephp2.txt.\n");
$zip->addFile($thisdir . "/too.php","/bookfromproductfile.php");
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";

4. using Zip() libs

you can use PCLZIP . :

$files_to_zip = array(

$dir = 'd:/projectname/upload/docs/'; 
$new_files = array();
  foreach($files_to_zip as $value){
   $new_files[] = $dir.$value;
// Create PHP Object
$archive = new PclZip("");

$files_archive = $archive->add($new_files, PCLZIP_OPT_REMOVE_PATH, $dir, PCLZIP_OPT_ADD_PATH, 'myFiles');
if ($files_archive == 0) {
    die("Error : ".$archive->errorInfo(true));
    echo "Your Zip Archive Files Created";

5. Unpack a Zip Files

How to Unpack a Zip File using PHP?

$file =; 
$zip = new ZipArchive;
$zipped = $zip->open($file);
$path = pathinfo(realpath($file), PATHINFO_DIRNAME);
if ($zipped) {
  $extract = $zip->extractTo($path);
    echo "Your file extracted to $folder_name";
  } else {
    echo "your file not extracted";
  //close the zip

Extra Bonus:

downloading zip file from url using php

Read Also:  crud operations in php

$zip_file_name = "product-items-csv/".$cat_id."-box."."zip";
downloadZipFile($items['liveReportUrl'], $zip_file_name);

function downloadZipFile($url, $filepath){
    $fp = fopen($filepath, 'w');
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_FILE, $fp);
    $data = curl_exec($ch);

Angular 6 CRUD Operations Application Tutorials

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Top 5 Free Dynamic ZIP Generation Libraries in PHP.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Full form of Technologies Related
  2. Read Also:  How to pass vuejs id attributes using bootstrap popup modal
  3. Read Also:  Laravel 5/6/7 create custom helper Function
  4. Read Also:  Laravel Eloquent Useful Tips and Tricks
  5. Read Also:  PHP Laravel group concat operation
  6. Read Also:  laravel soft delete relationship Eloquent ORM
  7. Read Also:  PHP and Ajax Asynchronous File Upload using jQuery
  8. Read Also:  PHP Vue.js Live Search Box Using MySQL
  9. Read Also:  vue Check box binding Example
  10. Read Also:  jQuery black gradient background effect Hover Slider With CSS