This is documentation for Kohana v2.3.x.
Status | Draft |
---|---|
Todo | Needs updating from library to module |
The Archive Module is a convenient way of constructing Archives (Zip Files, Tar Files, etc) dynamically. It can persist them to the file system, or it can send the binary file directly to the user without saving to the hard drive.
Currently it supports Zip, GZip, BZip and Tar Archives.
This can be done in the application/config/config.php file using the 'modules' setting.
$config['modules'] => array ( MODPATH.'auth', MODPATH.'archive' )
Then you just have to instantiate the module to use it. For example:
$this->archive = new Archive;
4 drivers are currently available: Zip, GZip, BZip and Tar. The default one is Zip but to load another one just pass it to the constructor:
zip
- defaultgzip
bzip
tar
// Load GZip driver $this->archive = new Archive('gzip');
add($path, $name = NULL, $recursive = NULL)
adds files and directories to your archive. It accepts the following parameter:
$path
the path to the file or directory to add. Relative paths must be relative to the root website dir. $name
name to use for the given file or directory$recursive
add files recursively, used with directories - default FALSEThis will result in file.txt being added to the archive:
$this->archive->add("files/uploads/file.txt");
save($filename)
saves the archive you've been creating to the disk.
$filename
path to save the archive file. Relative paths must be relative to the root website dir.$this->archive->save("myarchive.zip");
download($filename)
offers the archive as a download to the user.
$filename
name to be given to the archive file$this->archive->download("myarchive.zip");