Creating and downloading ZIP files

You may wish to generate ZIP folders from your application and force a download for your users; for example, if you have a group of files, such as a press pack, which you wish to be kept together, or a set of CSV files. Saving them into a ZIP file and allowing a download is a great way to do this.

How to do it...

We're going to create a new file:

  • /path/to/codeigniter/application/controllers/zip.php

And copy the following code into it:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Zip extends CI_Controller { function __construct() { parent::__construct(); $this->load->helper('form'); $this->load->helper('url'); $this->load->library('zip'); } public function index() { redirect('zip/zipme'); ...

Get CodeIgniter 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.