Class CI_Zip - echiong/testRepo GitHub Wiki

##Class CI_Zip

Zip Compression Class

This class is based on a library I found at Zend: http://www.zend.com/codex.php?id=696&single=1

The original library is a little rough around the edges so I refactored it and added several additional methods -- Rick Ellis

Package: [[CodeIgniter<a href="Package CodeIgniter.Libraries.md">Libraries]]
Category: Encryption
Author: ExpressionEngine Dev Team
Link: http://codeigniter.com/user_guide/libraries/zip.html
Located at system/libraries/Zip.php

##Methods summary


public __construct ( )

Constructor


public add_dir ( mixed $directory )

Add Directory

Lets you add a virtual directory into which you can place files.

Parameters

$directory mixed
the directory name. Can be string or array


public array _get_mod_time ( string $dir )

Get file/directory modification time

If this is a newly created file/dir, we will set the time to 'now'

Parameters

$dir string
path to file

Returns array
filemtime/filemdate


public _add_dir ( string $dir, mixed $file_mtime, mixed $file_mdate )

Add Directory

Parameters

$dir string
the directory name

$file_mtime

$file_mdate


public add_data ( mixed $filepath, string $data = NULL )

Add Data to Zip

Lets you add files to the archive. If the path is included in the filename it will be placed within a directory. Make sure you use add_dir() first to create the folder.

Parameters

$filepath mixed

$data string


public _add_data ( string $filepath, string $data, mixed $file_mtime, mixed $file_mdate )

Add Data to Zip

Parameters

$filepath string
the file name/path

$data string
the data to be encoded

$file_mtime

$file_mdate


public boolean read_file ( mixed $path, mixed $preserve_filepath = FALSE )

Read the contents of a file and add it to the zip

Returns boolean


public boolean read_dir ( string $path, mixed $preserve_filepath = TRUE, mixed $root_path = NULL )

Read a directory and add it to the zip.

This function recursively reads a folder and everything it contains (including sub-folders) and creates a zip based on it. Whatever directory structure is in the original file path will be recreated in the zip file.

Parameters

$path string
path to source

$preserve_filepath

$root_path

Returns boolean


public binary get_zip ( )

Get the Zip file

Returns binary
string


public boolean archive ( string $filepath )

Write File to the specified directory

Lets you write a file

Parameters

$filepath string
the file name

Returns boolean


public boolean download ( string $filename = 'backup.zip' )

Download

Parameters

$filename string
the file name

Returns boolean


public clear_data ( )

Initialize Data

Lets you clear current zip data. Useful if you need to create multiple zips with different data.

<table class="summary" id="properties">
<caption>Properties summary</caption>
<tr data-order="zipdata" id="$zipdata">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$zipdata

''
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="directory" id="$directory">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$directory

''
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="entries" id="$entries">
	<td class="attributes"><code>
		public  
		integer
	</code></td>

	<td class="name">

$entries

0
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="file_num" id="$file_num">
	<td class="attributes"><code>
		public  
		integer
	</code></td>

	<td class="name">

$file_num

0
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="offset" id="$offset">
	<td class="attributes"><code>
		public  
		integer
	</code></td>

	<td class="name">

$offset

0
#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
<tr data-order="now" id="$now">
	<td class="attributes"><code>
		public  
		mixed
	</code></td>

	<td class="name">

$now

#
		<div class="description detailed">
			

		</div>
	</div></td>
</tr>
</table>
⚠️ **GitHub.com Fallback** ⚠️