summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/libraries
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2014-12-04 10:47:26 +0100
committerAndrey Andreev <narf@devilix.net>2014-12-04 10:47:26 +0100
commit309d7012a737f140076cabbe8873dc39f25331b2 (patch)
treee9daa4922715528b654e16433fa85578941cba07 /user_guide_src/source/libraries
parenta94c397768c5906e0e519dc5b473d0688048caaa (diff)
Zip library changes related to PR #3341
- Drop compression_encoding option, it requires PHP 5.4. - Change default compression_level to 2 as this was previously the hard-coded default. - Improve on the doc changes made in the PR.
Diffstat (limited to 'user_guide_src/source/libraries')
-rw-r--r--user_guide_src/source/libraries/zip.rst56
1 files changed, 35 insertions, 21 deletions
diff --git a/user_guide_src/source/libraries/zip.rst b/user_guide_src/source/libraries/zip.rst
index a6b98c2ac..0f255755e 100644
--- a/user_guide_src/source/libraries/zip.rst
+++ b/user_guide_src/source/libraries/zip.rst
@@ -25,7 +25,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
=============
@@ -52,6 +54,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 +70,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!';
@@ -70,7 +81,8 @@ Class Reference
$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 +91,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...';
@@ -88,18 +101,14 @@ Class Reference
The above example will place my_bio.txt inside a folder called personal.
- You can change the level of compression and encoding that is used by the gzcompress function during compression::
-
- $this->zip->compression_level = 0; // Disable compression
- $this->zip->compression_encoding = ZLIB_ENCODING_GZIP;
-
.. method:: add_dir($directory)
: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"
@@ -161,15 +170,16 @@ Class Reference
// 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)
@@ -177,8 +187,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
@@ -187,7 +198,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"
@@ -200,7 +212,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...';
@@ -213,8 +226,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...';