diff options
author | Andrey Andreev <narf@devilix.net> | 2015-01-12 16:23:26 +0100 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2015-01-12 16:23:26 +0100 |
commit | 45a8afaabc6d09ad59bbb3c89a6cdfe8cbc3312c (patch) | |
tree | 7ca4207099f9225b5ef74b31f48627a282e7fdf2 /user_guide_src/source/libraries/zip.rst | |
parent | cd94dd7e1d8969658810ccc4158a75d2936d0a44 (diff) | |
parent | 934d6d9797f4dadd4e4d05b12bc4d7309fedb6c3 (diff) |
Merge branch 'develop' into feature/session
Diffstat (limited to 'user_guide_src/source/libraries/zip.rst')
-rw-r--r-- | user_guide_src/source/libraries/zip.rst | 65 |
1 files changed, 42 insertions, 23 deletions
diff --git a/user_guide_src/source/libraries/zip.rst b/user_guide_src/source/libraries/zip.rst index 4ca14086a..b509236de 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 ============= @@ -41,7 +43,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 +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!'; @@ -69,8 +80,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 +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...'; @@ -93,8 +106,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 +124,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 +134,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 +165,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 +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 @@ -182,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" @@ -195,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...'; @@ -208,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...'; @@ -217,9 +236,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'); |