Home » Download Extract Zip Archives using PHP cURL

Download Extract Zip Archives using PHP cURL

Today, We want to share with you Download Extract Zip Archives using PHP cURL.In this post we will show you download and extract zip files using php, hear for How To Download & Extract Zip Archives in PHP we will give you demo and example for implement.In this post, we will learn about direct download folder as zip link using php curl with an example.

Download Extract Zip Archives using PHP cURL

There are the Following The simple About Download Extract Zip Archives using PHP cURL Full Information With Example and source code.

Read Also:  PHP Download Remote File from URL using CURL

As I will cover this Post with live Working example to develop Download a URL’s Content Using PHP CURL, so the create zip file in php for this example is following below.

PHP has the main libs Like as a Zip Archive Extension. We can display the php manual for step by step installing ZipArchive Extension. The simple usage of PHP ZipArchive extension is very easy.

PHP Zip Download

First Way to Download Zip file in PHP

Simple File Download Zip Archives using PHP

$url = "http://myDomain.com/fullpathtozipfile.zip";
$zipFile = "myFolder/zipfile.zip"; //Your Main Local Zip File Path
$zipResource = fopen($zipFile, "w");
// Get The Zip File From Server
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER,true);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($curl, CURLOPT_FILE, $zipResource);
$page = curl_exec($curl);
if(!$page) {
 echo "Error :- ".curl_error($curl);

Onther Way To Download Zip File

function downloadZipFile($url, $filepath){
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_HEADER, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
     $raw_file_data = curl_exec($ch);

        echo 'generated error:' . curl_error($ch);

     file_put_contents($filepath, $raw_file_data);
     return (filesize($filepath) > 0)? true : false;

downloadZipFile("http://www.doaminname.com/api/admin/download/product.ZIP", "allProductresult.zip");

Read Also:  Nodejs Login and Registration with PHP MySQL and SQLite Example

PHP Extract (Unzip) Files

/* first of all simple Open the Zip file */
$zip = new ZipArchive;
$extractPath = "your_data_zip_upload_path_to_extract";
if($zip->open($zipFile) != "true"){
 echo "Some Generated Error :- Sorry, Unable to open the Zip File";
/*here simple Extract Zip File */

Angular 6 CRUD Operations Application Tutorials

Read :


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

I hope you get an idea about Download Extract Zip Archives using PHP cURL.
I would like to have feedback on my Pakainfo.com 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.

Read Also:  Simple jQuery Form Validator validation

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Disable submit button until Ajax Completes Example
  2. Read Also:  Ng-Cloak Directive using Angular Example
  3. Read Also:  Update Data in MySQL Using PHP
  4. Read Also:  SQL Inner, Left, Right and Full Joins
  5. Read Also:  PHP CURL Download File example
  6. Read Also:  PHP Create zip archive and Download Zip File using ZipArchive
  7. Read Also:  PHP Dynamically QR Codes Generator Scannable Barcodes
  8. Read Also:  Download File from URL Using PHP
  9. Read Also:  Download Remote File via PHP CURL
  10. Read Also:  jquery Drag and Drop draggable droppable Example

Leave a Comment

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