blob: 1994e34626254fb6bfe52898b2d68f392fe0820d [file] [log] [blame]
admina59c2a12006-10-01 19:02:11 +00001<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html>
3<head>
4
5<title>Code Igniter User Guide</title>
6
7<style type='text/css' media='all'>@import url('../userguide.css');</style>
8<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
9
10<script type="text/javascript" src="../nav/nav.js"></script>
11<script type="text/javascript" src="../nav/prototype.lite.js"></script>
12<script type="text/javascript" src="../nav/moo.fx.js"></script>
13<script type="text/javascript">
14window.onload = function() {
15 myHeight = new fx.Height('nav', {duration: 400});
16 myHeight.hide();
17}
18</script>
19
20<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
21<meta http-equiv='expires' content='-1' />
22<meta http-equiv= 'pragma' content='no-cache' />
23<meta name='robots' content='all' />
24<meta name='author' content='Rick Ellis' />
25<meta name='description' content='Code Igniter User Guide' />
26
27</head>
28<body>
29
30<!-- START NAVIGATION -->
31<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
32<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
33<div id="masthead">
34<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
35<tr>
36<td><h1>Code Igniter User Guide Version 1.5.0</h1></td>
37<td id="breadcrumb_right"><a href="../toc.html">Full Table of Contents</a></td>
38</tr>
39</table>
40</div>
41<!-- END NAVIGATION -->
42
43
44<!-- START BREADCRUMB -->
45<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
46<tr>
47<td id="breadcrumb">
48<a href="http://www.codeigniter.com/">Code Igniter Home</a> &nbsp;&#8250;&nbsp;
49<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
50Zip Encoding Class
51</td>
52<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="www.codeigniter.com/user_guide/" />Search User Guide&nbsp; <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />&nbsp;<input type="submit" class="submit" name="sa" value="Go" /></form></td>
53</tr>
54</table>
55<!-- END BREADCRUMB -->
56
57<br clear="all" />
58
59
60<!-- START CONTENT -->
61<div id="content">
62
63
64<h1>Zip Encoding Class</h1>
admin70d553b2006-10-01 19:20:24 +000065<p>Code Igniter's Zip Encoding Class classes permit you to create Zip archives.</p>
admina59c2a12006-10-01 19:02:11 +000066
67
admin70d553b2006-10-01 19:20:24 +000068<h2>Initializing the Class</h2>
69<p>Like most other classes in Code Igniter, the Zip class is initialized in your controller using the <dfn>$this->load->library</dfn> function:</p>
70
71<code>$this->load->library('zip');</code>
72<p>Once loaded, the Parser library object will be available using: <dfn>$this->zip</dfn></p>
73
admin73fbde22006-10-01 19:26:15 +000074<h2>Usage Examples</h2>
admin70d553b2006-10-01 19:20:24 +000075
76<p>Simple example demonstrating how to compress a file and download it to your desktop.</p>
77
78<code>
79$name = 'mydata1.txt';<br />
80$data = 'A Data String!';<br />
81$this->zip->add_data($name, $data);<br />
82<br />
83$name = 'mydata2.txt';<br />
84$data = 'Another Data String!';<br />
85$this->zip->add_data($name, $data);<br />
86<br />
87
88$this->zip->download('my_backup.zip'); // Parameter contains name of the downloaded file
89</code>
90
91<p>If you would like to place your data into a folder just include the directory as part of the filename:</p>
92
93
94<code>
95$name = 'myfolder/mydata1.txt';<br />
96$data = 'A Data String!';<br />
97$this->zip->add_data($name, $data);<br />
98<br />
99$name = 'myfolder/mydata2.txt';<br />
100$data = 'Another Data String!';<br />
101$this->zip->add_data($name, $data);<br />
102<br />
103
104$this->zip->download('my_backup.zip'); // Parameter contains name of the downloaded file
105</code>
106
admin73fbde22006-10-01 19:26:15 +0000107<p>You can also pass your file data as an array:</p>
admin70d553b2006-10-01 19:20:24 +0000108
109
admin73fbde22006-10-01 19:26:15 +0000110<code>
111$data = array(<br />
112&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'myfolder/mydata1.txt' => 'A Data String!',<br />
113&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'myfolder/mydata2.txt' => 'Another Data String!'<br />
114&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
115<br />
116$this->zip->add_data($data);<br />
117<br />
118$this->zip->download('my_backup.zip'); // Parameter contains name of the downloaded file
119</code>
admina59c2a12006-10-01 19:02:11 +0000120
121
122
123
124
125</div>
126<!-- END CONTENT -->
127
128
129<div id="footer">
130<p>
131Previous Topic:&nbsp;&nbsp;<a href="validation.html">Validation Class</a>
132&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
133<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
134<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
135Next Topic:&nbsp;&nbsp;<a href="../helpers/array_helper.html">Array Helper</a>
136<p>
137<p><a href="http://www.codeigniter.com">Code Igniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2006 &nbsp;&middot;&nbsp; <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
138</div>
139
140</body>
141</html>