blob: 77cc45b38e1c10cc0b48f0596e1ffd1310d8f554 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev0ea39292011-12-25 18:48:46 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev0ea39292011-12-25 18:48:46 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
Andrey Andreev1841e6b2012-01-24 15:30:01 +020012 * bundled with this package in the files license.txt / license.rst. It is
Derek Jonesf4a4bd82011-10-20 12:18:42 -050013 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
Derek Allard2067d1a2008-11-13 22:59:24 +000029/**
30 * Zip Compression Class
31 *
32 * This class is based on a library I found at Zend:
33 * http://www.zend.com/codex.php?id=696&single=1
34 *
35 * The original library is a little rough around the edges so I
36 * refactored it and added several additional methods -- Rick Ellis
37 *
38 * @package CodeIgniter
39 * @subpackage Libraries
40 * @category Encryption
Derek Jonesf4a4bd82011-10-20 12:18:42 -050041 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000042 * @link http://codeigniter.com/user_guide/libraries/zip.html
43 */
vkeranov95b2f4f2012-06-16 20:37:11 +030044class CI_Zip {
Derek Allard2067d1a2008-11-13 22:59:24 +000045
Timothy Warren86611db2012-04-27 10:06:25 -040046 /**
47 * Zip data in string form
48 *
49 * @var string
50 */
Andrey Andreev0ea39292011-12-25 18:48:46 +020051 public $zipdata = '';
Andrey Andreev56454792012-05-17 14:32:19 +030052
Timothy Warren86611db2012-04-27 10:06:25 -040053 /**
54 * Zip data for a directory in string form
55 *
56 * @var string
57 */
Andrey Andreev0ea39292011-12-25 18:48:46 +020058 public $directory = '';
Andrey Andreev56454792012-05-17 14:32:19 +030059
Timothy Warren86611db2012-04-27 10:06:25 -040060 /**
61 * Number of files/folder in zip file
62 *
63 * @var int
64 */
Andrey Andreev0ea39292011-12-25 18:48:46 +020065 public $entries = 0;
Andrey Andreev56454792012-05-17 14:32:19 +030066
Timothy Warren86611db2012-04-27 10:06:25 -040067 /**
68 * Number of files in zip
69 *
70 * @var int
71 */
Andrey Andreev0ea39292011-12-25 18:48:46 +020072 public $file_num = 0;
Andrey Andreev56454792012-05-17 14:32:19 +030073
Timothy Warren86611db2012-04-27 10:06:25 -040074 /**
75 * relative offset of local header
76 *
77 * @var int
78 */
Andrey Andreev0ea39292011-12-25 18:48:46 +020079 public $offset = 0;
Andrey Andreev56454792012-05-17 14:32:19 +030080
Timothy Warren86611db2012-04-27 10:06:25 -040081 /**
82 * Reference to time at init
83 *
84 * @var int
85 */
Andrey Andreev0ea39292011-12-25 18:48:46 +020086 public $now;
Derek Allard2067d1a2008-11-13 22:59:24 +000087
Timothy Warren86611db2012-04-27 10:06:25 -040088 /**
89 * Initialize zip compression class
90 *
Andrey Andreev56454792012-05-17 14:32:19 +030091 * @return void
Timothy Warren86611db2012-04-27 10:06:25 -040092 */
Greg Akera9263282010-11-10 15:26:43 -060093 public function __construct()
Derek Allard2067d1a2008-11-13 22:59:24 +000094 {
Greg Aker5ed19b42010-03-19 12:13:14 -050095 $this->now = time();
Andrey Andreevbb2e5182012-03-26 13:58:12 +030096 log_message('debug', 'Zip Compression Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +000097 }
98
99 // --------------------------------------------------------------------
100
101 /**
102 * Add Directory
103 *
104 * Lets you add a virtual directory into which you can place files.
105 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000106 * @param mixed the directory name. Can be string or array
107 * @return void
108 */
Andrey Andreev0ea39292011-12-25 18:48:46 +0200109 public function add_dir($directory)
Derek Allard2067d1a2008-11-13 22:59:24 +0000110 {
Andrey Andreev6c308b72012-02-02 22:03:53 +0200111 foreach ( (array) $directory as $dir)
Derek Allard2067d1a2008-11-13 22:59:24 +0000112 {
Andrey Andreevcfbd15b2012-01-08 06:41:41 +0200113 if ( ! preg_match('|.+/$|', $dir))
Derek Allard2067d1a2008-11-13 22:59:24 +0000114 {
115 $dir .= '/';
116 }
117
Greg Aker5ed19b42010-03-19 12:13:14 -0500118 $dir_time = $this->_get_mod_time($dir);
Greg Aker5ed19b42010-03-19 12:13:14 -0500119 $this->_add_dir($dir, $dir_time['file_mtime'], $dir_time['file_mdate']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000120 }
121 }
122
Barry Mienydd671972010-10-04 16:33:58 +0200123 // --------------------------------------------------------------------
Greg Aker5ed19b42010-03-19 12:13:14 -0500124
125 /**
Andrey Andreev6c308b72012-02-02 22:03:53 +0200126 * Get file/directory modification time
Barry Mienydd671972010-10-04 16:33:58 +0200127 *
Andrey Andreev6c308b72012-02-02 22:03:53 +0200128 * If this is a newly created file/dir, we will set the time to 'now'
Greg Aker5ed19b42010-03-19 12:13:14 -0500129 *
Andrey Andreev6c308b72012-02-02 22:03:53 +0200130 * @param string path to file
131 * @return array filemtime/filemdate
Greg Aker5ed19b42010-03-19 12:13:14 -0500132 */
Andrey Andreevb9535c82011-12-26 16:21:17 +0200133 protected function _get_mod_time($dir)
Greg Aker5ed19b42010-03-19 12:13:14 -0500134 {
Thomas Traub98f85b12011-12-05 14:58:29 +0100135 // filemtime() may return false, but raises an error for non-existing files
Andrey Andreev6c308b72012-02-02 22:03:53 +0200136 $date = file_exists($dir) ? filemtime($dir) : getdate($this->now);
Andrey Andreev0ea39292011-12-25 18:48:46 +0200137
Andrey Andreevcfbd15b2012-01-08 06:41:41 +0200138 return array(
Andrey Andreev0ea39292011-12-25 18:48:46 +0200139 'file_mtime' => ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2,
140 'file_mdate' => (($date['year'] - 1980) << 9) + ($date['mon'] << 5) + $date['mday']
141 );
Greg Aker5ed19b42010-03-19 12:13:14 -0500142 }
143
Derek Allard2067d1a2008-11-13 22:59:24 +0000144 // --------------------------------------------------------------------
145
146 /**
147 * Add Directory
148 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000149 * @param string the directory name
Andrey Andreev6c308b72012-02-02 22:03:53 +0200150 * @param int
151 * @param int
Derek Allard2067d1a2008-11-13 22:59:24 +0000152 * @return void
153 */
Andrey Andreevb9535c82011-12-26 16:21:17 +0200154 protected function _add_dir($dir, $file_mtime, $file_mdate)
Barry Mienydd671972010-10-04 16:33:58 +0200155 {
Andrey Andreeve34f1a72012-01-10 22:41:52 +0200156 $dir = str_replace('\\', '/', $dir);
Derek Allard2067d1a2008-11-13 22:59:24 +0000157
158 $this->zipdata .=
Greg Aker5ed19b42010-03-19 12:13:14 -0500159 "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00"
160 .pack('v', $file_mtime)
161 .pack('v', $file_mdate)
Derek Allard2067d1a2008-11-13 22:59:24 +0000162 .pack('V', 0) // crc32
163 .pack('V', 0) // compressed filesize
164 .pack('V', 0) // uncompressed filesize
165 .pack('v', strlen($dir)) // length of pathname
166 .pack('v', 0) // extra field length
167 .$dir
168 // below is "data descriptor" segment
169 .pack('V', 0) // crc32
170 .pack('V', 0) // compressed filesize
171 .pack('V', 0); // uncompressed filesize
172
173 $this->directory .=
Greg Aker5ed19b42010-03-19 12:13:14 -0500174 "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00"
175 .pack('v', $file_mtime)
176 .pack('v', $file_mdate)
Derek Allard2067d1a2008-11-13 22:59:24 +0000177 .pack('V',0) // crc32
178 .pack('V',0) // compressed filesize
179 .pack('V',0) // uncompressed filesize
180 .pack('v', strlen($dir)) // length of pathname
181 .pack('v', 0) // extra field length
182 .pack('v', 0) // file comment length
183 .pack('v', 0) // disk number start
184 .pack('v', 0) // internal file attributes
185 .pack('V', 16) // external file attributes - 'directory' bit set
186 .pack('V', $this->offset) // relative offset of local header
187 .$dir;
188
189 $this->offset = strlen($this->zipdata);
190 $this->entries++;
191 }
Barry Mienydd671972010-10-04 16:33:58 +0200192
Derek Allard2067d1a2008-11-13 22:59:24 +0000193 // --------------------------------------------------------------------
194
195 /**
196 * Add Data to Zip
197 *
198 * Lets you add files to the archive. If the path is included
Andrey Andreev0b5a4862012-02-29 23:44:00 +0200199 * in the filename it will be placed within a directory. Make
Derek Allard2067d1a2008-11-13 22:59:24 +0000200 * sure you use add_dir() first to create the folder.
201 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 * @param mixed
203 * @param string
204 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200205 */
Andrey Andreev0ea39292011-12-25 18:48:46 +0200206 public function add_data($filepath, $data = NULL)
Barry Mienydd671972010-10-04 16:33:58 +0200207 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000208 if (is_array($filepath))
209 {
210 foreach ($filepath as $path => $data)
211 {
Barry Mienydd671972010-10-04 16:33:58 +0200212 $file_data = $this->_get_mod_time($path);
Greg Aker5ed19b42010-03-19 12:13:14 -0500213 $this->_add_data($path, $data, $file_data['file_mtime'], $file_data['file_mdate']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000214 }
215 }
216 else
217 {
Greg Aker5ed19b42010-03-19 12:13:14 -0500218 $file_data = $this->_get_mod_time($filepath);
Greg Aker5ed19b42010-03-19 12:13:14 -0500219 $this->_add_data($filepath, $data, $file_data['file_mtime'], $file_data['file_mdate']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000220 }
221 }
222
223 // --------------------------------------------------------------------
224
225 /**
226 * Add Data to Zip
227 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000228 * @param string the file name/path
229 * @param string the data to be encoded
Andrey Andreev6c308b72012-02-02 22:03:53 +0200230 * @param int
231 * @param int
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200233 */
Andrey Andreevb9535c82011-12-26 16:21:17 +0200234 protected function _add_data($filepath, $data, $file_mtime, $file_mdate)
Derek Allard2067d1a2008-11-13 22:59:24 +0000235 {
Andrey Andreevcfbd15b2012-01-08 06:41:41 +0200236 $filepath = str_replace('\\', '/', $filepath);
Derek Allard2067d1a2008-11-13 22:59:24 +0000237
238 $uncompressed_size = strlen($data);
Derek Jones37f4b9c2011-07-01 17:56:50 -0500239 $crc32 = crc32($data);
Andrey Andreevcfbd15b2012-01-08 06:41:41 +0200240 $gzdata = substr(gzcompress($data), 2, -4);
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 $compressed_size = strlen($gzdata);
242
243 $this->zipdata .=
Greg Aker5ed19b42010-03-19 12:13:14 -0500244 "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00"
245 .pack('v', $file_mtime)
246 .pack('v', $file_mdate)
Derek Allard2067d1a2008-11-13 22:59:24 +0000247 .pack('V', $crc32)
248 .pack('V', $compressed_size)
249 .pack('V', $uncompressed_size)
250 .pack('v', strlen($filepath)) // length of filename
251 .pack('v', 0) // extra field length
252 .$filepath
253 .$gzdata; // "file data" segment
254
255 $this->directory .=
Greg Aker5ed19b42010-03-19 12:13:14 -0500256 "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00"
257 .pack('v', $file_mtime)
258 .pack('v', $file_mdate)
Derek Allard2067d1a2008-11-13 22:59:24 +0000259 .pack('V', $crc32)
260 .pack('V', $compressed_size)
261 .pack('V', $uncompressed_size)
262 .pack('v', strlen($filepath)) // length of filename
263 .pack('v', 0) // extra field length
264 .pack('v', 0) // file comment length
265 .pack('v', 0) // disk number start
266 .pack('v', 0) // internal file attributes
267 .pack('V', 32) // external file attributes - 'archive' bit set
268 .pack('V', $this->offset) // relative offset of local header
269 .$filepath;
270
271 $this->offset = strlen($this->zipdata);
272 $this->entries++;
273 $this->file_num++;
274 }
Barry Mienydd671972010-10-04 16:33:58 +0200275
Derek Allard2067d1a2008-11-13 22:59:24 +0000276 // --------------------------------------------------------------------
277
278 /**
279 * Read the contents of a file and add it to the zip
280 *
Andrey Andreev6c308b72012-02-02 22:03:53 +0200281 * @param string
282 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000283 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200284 */
Andrey Andreev0ea39292011-12-25 18:48:46 +0200285 public function read_file($path, $preserve_filepath = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000286 {
287 if ( ! file_exists($path))
288 {
289 return FALSE;
290 }
291
292 if (FALSE !== ($data = file_get_contents($path)))
293 {
Andrey Andreevcfbd15b2012-01-08 06:41:41 +0200294 $name = str_replace('\\', '/', $path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000295 if ($preserve_filepath === FALSE)
296 {
Andrey Andreevcfbd15b2012-01-08 06:41:41 +0200297 $name = preg_replace('|.*/(.+)|', '\\1', $name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000298 }
299
300 $this->add_data($name, $data);
301 return TRUE;
302 }
Andrey Andreevcfbd15b2012-01-08 06:41:41 +0200303
Derek Allard2067d1a2008-11-13 22:59:24 +0000304 return FALSE;
305 }
306
307 // ------------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200308
Derek Allard2067d1a2008-11-13 22:59:24 +0000309 /**
310 * Read a directory and add it to the zip.
311 *
312 * This function recursively reads a folder and everything it contains (including
Andrey Andreev16d80662012-01-20 13:26:49 +0200313 * sub-folders) and creates a zip based on it. Whatever directory structure
Derek Allard2067d1a2008-11-13 22:59:24 +0000314 * is in the original file path will be recreated in the zip file.
315 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 * @param string path to source
Andrey Andreev6c308b72012-02-02 22:03:53 +0200317 * @param bool
318 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000319 * @return bool
Phil Sturgeon26872de2010-05-11 11:41:59 +0100320 */
Andrey Andreev0ea39292011-12-25 18:48:46 +0200321 public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL)
Phil Sturgeon26872de2010-05-11 11:41:59 +0100322 {
tschechnikerc8175be2012-04-04 14:47:30 +0300323 $path = rtrim($path, '/\\').DIRECTORY_SEPARATOR;
Derek Jones2735b3e2010-05-11 08:58:21 -0500324 if ( ! $fp = @opendir($path))
Derek Allard2067d1a2008-11-13 22:59:24 +0000325 {
Phil Sturgeon26872de2010-05-11 11:41:59 +0100326 return FALSE;
327 }
328
329 // Set the original directory root for child dir's to use as relative
330 if ($root_path === NULL)
331 {
tschechnikerc8175be2012-04-04 14:47:30 +0300332 $root_path = dirname($path).DIRECTORY_SEPARATOR;
Phil Sturgeon26872de2010-05-11 11:41:59 +0100333 }
334
335 while (FALSE !== ($file = readdir($fp)))
336 {
Andrey Andreev0ea39292011-12-25 18:48:46 +0200337 if ($file[0] === '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000338 {
Phil Sturgeon26872de2010-05-11 11:41:59 +0100339 continue;
340 }
341
342 if (@is_dir($path.$file))
343 {
tschechnikerc8175be2012-04-04 14:47:30 +0300344 $this->read_dir($path.$file.DIRECTORY_SEPARATOR, $preserve_filepath, $root_path);
Phil Sturgeon26872de2010-05-11 11:41:59 +0100345 }
Andrey Andreev16d80662012-01-20 13:26:49 +0200346 elseif (FALSE !== ($data = file_get_contents($path.$file)))
Phil Sturgeon26872de2010-05-11 11:41:59 +0100347 {
Tobias Tschech9664cc92012-04-04 15:22:33 +0300348 $name = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $path);
Andrey Andreev16d80662012-01-20 13:26:49 +0200349 if ($preserve_filepath === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 {
Andrey Andreev16d80662012-01-20 13:26:49 +0200351 $name = str_replace($root_path, '', $name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000352 }
Andrey Andreev16d80662012-01-20 13:26:49 +0200353 $this->add_data($name.$file, $data);
Derek Allard2067d1a2008-11-13 22:59:24 +0000354 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000355 }
Derek Jones2735b3e2010-05-11 08:58:21 -0500356
Andrey Andreev6c308b72012-02-02 22:03:53 +0200357 closedir($fp);
Phil Sturgeon26872de2010-05-11 11:41:59 +0100358 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000359 }
360
361 // --------------------------------------------------------------------
362
363 /**
364 * Get the Zip file
365 *
Andrey Andreev6c308b72012-02-02 22:03:53 +0200366 * @return string (binary encoded)
Barry Mienydd671972010-10-04 16:33:58 +0200367 */
Andrey Andreev0ea39292011-12-25 18:48:46 +0200368 public function get_zip()
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 {
370 // Is there any data to return?
Andrey Andreevcfbd15b2012-01-08 06:41:41 +0200371 if ($this->entries === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000372 {
373 return FALSE;
374 }
375
Andrey Andreev0ea39292011-12-25 18:48:46 +0200376 return $this->zipdata
Andrey Andreev6c308b72012-02-02 22:03:53 +0200377 .$this->directory."\x50\x4b\x05\x06\x00\x00\x00\x00"
378 .pack('v', $this->entries) // total # of entries "on this disk"
379 .pack('v', $this->entries) // total # of entries overall
380 .pack('V', strlen($this->directory)) // size of central dir
381 .pack('V', strlen($this->zipdata)) // offset to start of central dir
382 ."\x00\x00"; // .zip file comment length
Derek Allard2067d1a2008-11-13 22:59:24 +0000383 }
Barry Mienydd671972010-10-04 16:33:58 +0200384
Derek Allard2067d1a2008-11-13 22:59:24 +0000385 // --------------------------------------------------------------------
386
387 /**
388 * Write File to the specified directory
389 *
390 * Lets you write a file
391 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000392 * @param string the file name
393 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200394 */
Andrey Andreev0ea39292011-12-25 18:48:46 +0200395 public function archive($filepath)
Derek Allard2067d1a2008-11-13 22:59:24 +0000396 {
397 if ( ! ($fp = @fopen($filepath, FOPEN_WRITE_CREATE_DESTRUCTIVE)))
398 {
399 return FALSE;
400 }
401
Barry Mienydd671972010-10-04 16:33:58 +0200402 flock($fp, LOCK_EX);
Derek Allard2067d1a2008-11-13 22:59:24 +0000403 fwrite($fp, $this->get_zip());
404 flock($fp, LOCK_UN);
405 fclose($fp);
406
Barry Mienydd671972010-10-04 16:33:58 +0200407 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000408 }
409
410 // --------------------------------------------------------------------
411
412 /**
413 * Download
414 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000415 * @param string the file name
Andrey Andreev0b5a4862012-02-29 23:44:00 +0200416 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +0000417 */
Andrey Andreev0ea39292011-12-25 18:48:46 +0200418 public function download($filename = 'backup.zip')
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 {
Andrey Andreeve34f1a72012-01-10 22:41:52 +0200420 if ( ! preg_match('|.+?\.zip$|', $filename))
Derek Allard2067d1a2008-11-13 22:59:24 +0000421 {
422 $filename .= '.zip';
423 }
424
Derek Allard2067d1a2008-11-13 22:59:24 +0000425 $CI =& get_instance();
426 $CI->load->helper('download');
Derek Allard8dc2c7c2009-12-07 16:07:15 +0000427 $get_zip = $this->get_zip();
Derek Allard8dc2c7c2009-12-07 16:07:15 +0000428 $zip_content =& $get_zip;
429
Derek Allard2067d1a2008-11-13 22:59:24 +0000430 force_download($filename, $zip_content);
431 }
432
433 // --------------------------------------------------------------------
434
435 /**
436 * Initialize Data
437 *
Andrey Andreev16d80662012-01-20 13:26:49 +0200438 * Lets you clear current zip data. Useful if you need to create
Derek Allard2067d1a2008-11-13 22:59:24 +0000439 * multiple zips with different data.
440 *
Andrew Podner4296a652012-12-17 07:51:15 -0500441 * @return CI_Zip
Barry Mienydd671972010-10-04 16:33:58 +0200442 */
Andrey Andreev0ea39292011-12-25 18:48:46 +0200443 public function clear_data()
Derek Allard2067d1a2008-11-13 22:59:24 +0000444 {
445 $this->zipdata = '';
446 $this->directory = '';
447 $this->entries = 0;
448 $this->file_num = 0;
449 $this->offset = 0;
Andrey Andreevb9535c82011-12-26 16:21:17 +0200450 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 }
Barry Mienydd671972010-10-04 16:33:58 +0200452
Derek Allard2067d1a2008-11-13 22:59:24 +0000453}
454
455/* End of file Zip.php */
Andrey Andreev0336dc22012-03-20 15:34:28 +0200456/* Location: ./system/libraries/Zip.php */