summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/libraries/zip.rst
diff options
context:
space:
mode:
Diffstat (limited to 'user_guide_src/source/libraries/zip.rst')
-rw-r--r--user_guide_src/source/libraries/zip.rst70
1 files changed, 44 insertions, 26 deletions
diff --git a/user_guide_src/source/libraries/zip.rst b/user_guide_src/source/libraries/zip.rst
index 4ca14086a..ce70e6c88 100644
--- a/user_guide_src/source/libraries/zip.rst
+++ b/user_guide_src/source/libraries/zip.rst
@@ -2,9 +2,8 @@
Zip Encoding Class
##################
-CodeIgniter's Zip Encoding Class classes permit you to create Zip
-archives. Archives can be downloaded to your desktop or saved to a
-directory.
+CodeIgniter's Zip Encoding Class permits you to create Zip archives.
+Archives can be downloaded to your desktop or saved to a directory.
.. contents::
:local:
@@ -25,7 +24,9 @@ your controller using the $this->load->library function::
$this->load->library('zip');
-Once loaded, the Zip library object will be available using: $this->zip
+Once loaded, the Zip library object will be available using:
+
+ $this->zip
Usage Example
=============
@@ -41,7 +42,7 @@ your server, and download it to your desktop.
$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');
+ $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');
@@ -52,6 +53,14 @@ Class Reference
.. class:: CI_Zip
+ .. attribute:: $compression_level = 2
+
+ The compression level to use.
+
+ It can range from 0 to 9, with 9 being the highest and 0 effectively disabling compression::
+
+ $this->zip->compression_level = 0;
+
.. method:: add_data($filepath[, $data = NULL])
:param mixed $filepath: A single file path or an array of file => data pairs
@@ -60,7 +69,8 @@ Class Reference
Adds data to the Zip archive. Can work both in single and multiple files mode.
- When adding a single file, the first parameter must contain the name you would like given to the file and the second must contain the file contents::
+ When adding a single file, the first parameter must contain the name you would
+ like given to the file and the second must contain the file contents::
$name = 'mydata1.txt';
$data = 'A Data String!';
@@ -69,8 +79,9 @@ Class Reference
$name = 'mydata2.txt';
$data = 'Another Data String!';
$this->zip->add_data($name, $data);
-
- When adding multiple files, the first parameter must contain *file => contents* pairs and the second parameter is ignored::
+
+ When adding multiple files, the first parameter must contain *file => contents* pairs
+ and the second parameter is ignored::
$data = array(
'mydata1.txt' => 'A Data String!',
@@ -79,7 +90,8 @@ Class Reference
$this->zip->add_data($data);
- If you would like your compressed data organized into sub-directories, simply include the path as part of the filename(s)::
+ If you would like your compressed data organized into sub-directories, simply include
+ the path as part of the filename(s)::
$name = 'personal/my_bio.txt';
$data = 'I was born in an elevator...';
@@ -93,8 +105,9 @@ Class Reference
:param mixed $directory: Directory name string or an array of multiple directories
:rtype: 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::
+ 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"
@@ -110,7 +123,7 @@ Class Reference
$path = '/path/to/photo.jpg';
- $this->zip->read_file($path);
+ $this->zip->read_file($path);
// Download the file to your desktop. Name it "my_backup.zip"
$this->zip->download('my_backup.zip');
@@ -120,7 +133,7 @@ Class Reference
$path = '/path/to/photo.jpg';
- $this->zip->read_file($path, TRUE);
+ $this->zip->read_file($path, TRUE);
// Download the file to your desktop. Name it "my_backup.zip"
$this->zip->download('my_backup.zip');
@@ -151,20 +164,21 @@ Class Reference
$path = '/path/to/your/directory/';
- $this->zip->read_dir($path);
+ $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::
+ 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.
+ 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.
.. method:: archive($filepath)
@@ -172,8 +186,9 @@ Class Reference
:returns: TRUE on success, FALSE on failure
:rtype: bool
- Writes the Zip-encoded file to a directory on your server. Submit a valid server path ending in the file name.
- Make sure the directory is writable (755 is usually OK). Example::
+ Writes the Zip-encoded file to a directory on your server. Submit a valid server path
+ ending in the file name. Make sure the directory is writable (755 is usually OK).
+ Example::
$this->zip->archive('/path/to/folder/myarchive.zip'); // Creates a file named myarchive.zip
@@ -182,7 +197,8 @@ Class Reference
:param string $filename: Archive file name
:rtype: void
- Causes the Zip file to be downloaded from your server. You must pass the name you would like the zip file called. Example::
+ Causes the Zip file to be downloaded from your server.
+ You must pass the name you would like the zip file called. Example::
$this->zip->download('latest_stuff.zip'); // File will be named "latest_stuff.zip"
@@ -195,7 +211,8 @@ Class Reference
:returns: Zip file content
:rtype: string
- Returns the Zip-compressed file data. Generally you will not need this method unless you want to do something unique with the data. Example::
+ Returns the Zip-compressed file data. Generally you will not need this method unless you
+ want to do something unique with the data. Example::
$name = 'my_bio.txt';
$data = 'I was born in an elevator...';
@@ -208,8 +225,9 @@ Class Reference
:rtype: void
- 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::
+ 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...';
@@ -217,9 +235,9 @@ Class Reference
$this->zip->add_data($name, $data);
$zip_file = $this->zip->get_zip();
- $this->zip->clear_data();
+ $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'); \ No newline at end of file
+ $this->zip->download('myphotos.zip');