EllisLab/CodeIgniter — pull request #3206 by patricksavalle (2014-08-27 13:28:07+00:00)
Title: Create zip_helper.php

Functionality that is not in PHP or CI: create zip-file in memory. Took it directly from this project: https://github.com/phpmyadmin/phpmyadmin/blob/master/libraries/zip.lib.php

Used it in our software successfully.

Found it here: http://stackoverflow.com/questions/1189019/manipulate-an-archive-in-memory-with-php-without-creating-a-temporary-file-on-d

Use:

//create the zip
$zip = new zipfile();

//add files to the zip, passing file contents, not actual files
$zip->addFile($file_content, $file_name);

...

//prepare the proper content type
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=my_archive.zip");
header("Content-Description: Files of an applicant");

//get the zip content and send it back to the browser
exit( $zip->file() );