Create and Download Zip File using CodeIgniter

A ZIP file is an archive that contains one or more files or directories compressed. Zip files make it easy to keep related files or directories together and make transporting, e-mailing, downloading, and storing data and software faster and more efficient. In this tutorial, We have share how to Create and Download Zip Files using CodeIgniter zip library. This example demonstrates how to compress a file, save it to a folder on your server, and download your computer.
Step 1: load class
The Zip class is initialised in your controller using the $this->load->library function:
Once loaded, the Zip library object will be available using:
  • read_file() – This method will read the content of a file and it will add into Zip.
  • archive() – This method will write file to the specified directory, in this method we have to define file name with complete path.
  • download() – This method will download created Zip file in our local, in this method we have to define zip file name.
Step 2: Create a controller file
Next create a controller file named “Zipfile.php” inside “application/controllers” folder.
Step 3: Create a view file
Create a view file named “index.php” inside “application/views/zipfile folder