Skip to content

Instantly share code, notes, and snippets.

@abdullahbutt
Created November 10, 2013 20:22
Show Gist options
  • Select an option

  • Save abdullahbutt/7403431 to your computer and use it in GitHub Desktop.

Select an option

Save abdullahbutt/7403431 to your computer and use it in GitHub Desktop.
CI Zip Files for Download
Save Bandwidth by Zipping Files That Users Need to Download
To save bandwidth, it's a fairly common practice to compress or 'ZIP' files before you download them. That's not something I've ever done, and I wouldn't know how to go about it. On the other hand, CI has a nice facility that allows you to produce zipped files with four lines of code:
$name = 'mydata1.txt';
$data = 'the contents of my file…………';
$this->zip->add_data($name, $data);
$this->zip->archive('c:/my_backup.zip');
Run this, and you find a ZIP archive on your C drive containing one file. Your ZIP filer reader will unzip it and produce the original data for you.
People who use your site won't know that you've produced this impressive result so easily. They'll be impressed! Your site will save bandwidth. You did it in minutes rather than hours.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment