This example demonstrates how to compress a file, save it to a folder on
your server, and download it to your desktop.

$name='mydata1.txt';$data='A Data String!';$this->zip->add_data($name,$data);// Write the zip file to a folder on your server. Name it "my_backup.zip"$this->zip->archive('/path/to/directory/my_backup.zip');// Download the file to your desktop. Name it "my_backup.zip"$this->zip->download('my_backup.zip');

$directory (mixed) – Directory name string or an array of multiple directories

Return type:

void

Permits you to add a directory. Usually this method is unnecessary since you can place
your data into directories when using $this->zip->add_data(), but if you would like
to create an empty directory you can do so:

$this->zip->add_dir('myfolder');// Creates a directory called "myfolder"

$root_path (string) – Part of the path to exclude from the archive directory

Returns:

TRUE on success, FALSE on failure

Return type:

bool

Permits you to compress a directory (and its contents) that already exists somewhere on your server.
Supply a path to the directory and the zip class will recursively read and recreate it as a Zip archive.
All files contained within the supplied path will be encoded, as will any sub-directories contained within it. Example:

$path='/path/to/your/directory/';$this->zip->read_dir($path);// Download the file to your desktop. Name it "my_backup.zip"$this->zip->download('my_backup.zip');

By default the Zip archive will place all directories listed in the first parameter
inside the zip. If you want the tree preceding the target directory to be ignored,
you can pass FALSE (boolean) in the second parameter. Example:

$path='/path/to/your/directory/';$this->zip->read_dir($path,FALSE);

This will create a ZIP with a directory named “directory” inside, then all sub-directories
stored correctly inside that, but will not include the /path/to/your part of the path.

The Zip class caches your zip data so that it doesn’t need to recompile the Zip archive
for each method you use above. If, however, you need to create multiple Zip archives,
each with different data, you can clear the cache between calls. Example:

$name='my_bio.txt';$data='I was born in an elevator...';$this->zip->add_data($name,$data);$zip_file=$this->zip->get_zip();$this->zip->clear_data();$name='photo.jpg';$this->zip->read_file("/path/to/photo.jpg");// Read the file's contents$this->zip->download('myphotos.zip');