PHP Class CI_Zip, TastyIgniter

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
Author: EllisLab Dev Team
显示文件 Open project: tastyigniter/tastyigniter Class Usage Examples

Public Properties

Property Type Description
$compression_level integer Ranges from 0 to 9, with 9 being the highest level.
$directory string Zip data for a directory in string form
$entries integer Number of files/folder in zip file
$file_num integer Number of files in zip
$now integer Reference to time at init
$offset integer relative offset of local header
$zipdata string Zip data in string form

Public Methods

Method Description
__construct ( ) : void Initialize zip compression class
add_data ( mixed $filepath, string $data = NULL ) : void Add Data to Zip
add_dir ( mixed $directory ) : void Add Directory
archive ( string $filepath ) : boolean Write File to the specified directory
clear_data ( ) : CI_Zip Initialize Data
download ( string $filename = 'backup.zip' ) : void Download
get_zip ( ) : string Get the Zip file
read_dir ( string $path, boolean $preserve_filepath = TRUE, string $root_path = NULL ) : boolean Read a directory and add it to the zip.
read_file ( string $path, boolean $archive_filepath = FALSE ) : boolean Read the contents of a file and add it to the zip

Protected Methods

Method Description
_add_data ( string $filepath, string $data, integer $file_mtime, integer $file_mdate ) : void Add Data to Zip
_add_dir ( string $dir, integer $file_mtime, integer $file_mdate ) : void Add Directory
_get_mod_time ( string $dir ) : array Get file/directory modification time

Method Details

__construct() public method

Initialize zip compression class
public __construct ( ) : void
return void

_add_data() protected method

Add Data to Zip
protected _add_data ( string $filepath, string $data, integer $file_mtime, integer $file_mdate ) : void
$filepath string the file name/path
$data string the data to be encoded
$file_mtime integer
$file_mdate integer
return void

_add_dir() protected method

Add Directory
protected _add_dir ( string $dir, integer $file_mtime, integer $file_mdate ) : void
$dir string the directory name
$file_mtime integer
$file_mdate integer
return void

_get_mod_time() protected method

If this is a newly created file/dir, we will set the time to 'now'
protected _get_mod_time ( string $dir ) : array
$dir string path to file
return array filemtime/filemdate

add_data() public method

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.
public add_data ( mixed $filepath, string $data = NULL ) : void
$filepath mixed A single filepath or an array of file => data pairs
$data string Single file contents
return void

add_dir() public method

Lets you add a virtual directory into which you can place files.
public add_dir ( mixed $directory ) : void
$directory mixed the directory name. Can be string or array
return void

archive() public method

Lets you write a file
public archive ( string $filepath ) : boolean
$filepath string the file name
return boolean

clear_data() public method

Lets you clear current zip data. Useful if you need to create multiple zips with different data.
public clear_data ( ) : CI_Zip
return CI_Zip

download() public method

Download
public download ( string $filename = 'backup.zip' ) : void
$filename string the file name
return void

get_zip() public method

Get the Zip file
public get_zip ( ) : string
return string (binary encoded)

read_dir() public method

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.
public read_dir ( string $path, boolean $preserve_filepath = TRUE, string $root_path = NULL ) : boolean
$path string path to source directory
$preserve_filepath boolean
$root_path string
return boolean

read_file() public method

Read the contents of a file and add it to the zip
public read_file ( string $path, boolean $archive_filepath = FALSE ) : boolean
$path string
$archive_filepath boolean
return boolean

Property Details

$compression_level public_oe property

Ranges from 0 to 9, with 9 being the highest level.
public int $compression_level
return integer

$directory public_oe property

Zip data for a directory in string form
public string $directory
return string

$entries public_oe property

Number of files/folder in zip file
public int $entries
return integer

$file_num public_oe property

Number of files in zip
public int $file_num
return integer

$now public_oe property

Reference to time at init
public int $now
return integer

$offset public_oe property

relative offset of local header
public int $offset
return integer

$zipdata public_oe property

Zip data in string form
public string $zipdata
return string