PHP Create zip archive and Download Zip File using ZipArchive

PHP Create zip archive and Download Zip File using ZipArchive

PHP Create zip archive and Download Zip File using ZipArchive

In this Post We Will Explain About is PHP Create zip archive and Download Zip File using ZipArchive With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to How to create and download a Zip file with PHPExample

In this post we will show you Best way to implement Create zip archive from directory in PHP, hear for How to create a zip archive file for download in Laravel PHPwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Read Also:  Laravel 6 Set Active Navigation Menu Example

First of all create a simple php file to archive all the data files and folder and save the all the data particuler destination path and here save successfully.!here live.jpg and live2.jpg 2 fils here available and php to create a ZipArchive simple and best way to zip created./* create simple a all the data compressed zip file using PHP */

create sure We have two image simple file should here available near like as a index.php file:

Read Also:  Blinking text CSS Animation

1) live1.jpg

2) live2.jpg

<?php
function path_make_zip($files = array(), $save_path = '', $overwrite = false) {

   if(file_exists($save_path) && !$overwrite) { return false; }

   $check_files = [];
   if(is_array($files)) {
      foreach($files as $file) {
         if(file_exists($file)) {
            $check_files[] = $file;
         }
      }
   }

   if(count($check_files)) {
      $zip = new ZipArchive();
      if($zip->open($save_path,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
         return false;
      }

      foreach($check_files as $file) {
         $zip->addFile($file,$file);
      }

      $zip->close();
      return file_exists($save_path);
   }else{
      return false;
   }
}

$your_filename = 'live-archive.zip';
$all_filestozip = ['live1.jpg', 'live2.jpg'];
$result = path_make_zip($all_filestozip, $your_filename);

header("Content-Disposition: attachment; filename=\"".$your_filename."\"");
header("Content-Length: ".filesize($your_filename));
readfile($your_filename);

?>

Now And the last steps to We can run above PHP whole file and simple check it.

Read Also:  Vue js Laravel 5.8 File Upload Tutorial

Example

I hope you have Got What is How to create a zip archive file for download in Laravel PHP And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

Your email address will not be published. Required fields are marked *