Zip Encoding Class
Code Igniter's Zip Encoding Class classes permit you to create Zip archives.
Initializing the Class
Like most other classes in Code Igniter, the Zip class is initialized in your controller using the $this->load->library function:
$this->load->library('zip');
Once loaded, the Parser library object will be available using: $this->zip
Usage Examples
Simple example demonstrating how to compress a file and download it to your desktop.
$name = 'mydata1.txt';
$data = 'A Data String!';
$this->zip->add_data($name, $data);
$name = 'mydata2.txt';
$data = 'Another Data String!';
$this->zip->add_data($name, $data);
$this->zip->download('my_backup.zip'); // Parameter contains name of the downloaded file
If you would like to place your data into a folder just include the directory as part of the filename:
$name = 'myfolder/mydata1.txt';
$data = 'A Data String!';
$this->zip->add_data($name, $data);
$name = 'myfolder/mydata2.txt';
$data = 'Another Data String!';
$this->zip->add_data($name, $data);
$this->zip->download('my_backup.zip'); // Parameter contains name of the downloaded file
You can also pass your file data as an array:
$data = array(
'myfolder/mydata1.txt' => 'A Data String!',
'myfolder/mydata2.txt' => 'Another Data String!'
);
$this->zip->add_data($data);
$this->zip->download('my_backup.zip'); // Parameter contains name of the downloaded file