Method PclZip::add()
Overview
This method add files or folders in a PKZIP archive.
(PclZip >= 1.1)Synopsis
PclZip::add($filelist, [options list])
Arguments
$filelist :
An array of filenames or dirnames,
or
A string containing the a filename or a dirname,
or
A string containing a list of filename or dirname separated by a comma.optional arguments :
This method support the following optional arguments :
- PCLZIP_OPT_REMOVE_PATH
- PCLZIP_OPT_REMOVE_ALL_PATH
- PCLZIP_OPT_ADD_PATH
- PCLZIP_CB_PRE_ADD
- PCLZIP_CB_POST_ADD
- PCLZIP_OPT_NO_COMPRESSION
- PCLZIP_OPT_COMMENT
- PCLZIP_OPT_ADD_COMMENT
- PCLZIP_OPT_PREPEND_COMMENT
- PCLZIP_OPT_TEMP_FILE_THRESHOLD
- PCLZIP_OPT_TEMP_FILE_ON
- PCLZIP_OPT_TEMP_FILE_OFF
See chapter "Optional arguments" for more informations.Returned values
0
On error.
an array
An array file properties. (See "Returned values ")
Description :
This method adds in the existing PKZIP archive the files and folders set in the $filelist argument. When the name is a directory name, all the folder name and sub-folders are added and the filesystem structure is memorized.
Becareful that if a file already exist in an archive it is added at the end of the archive, but not automatically replaced.
If the archive does not exist, it is automatically created.The optional arguments gives the ability to modify the way PclZip add the files in the archive. The path can be removed or changed, the file can be added without any compression. Comments can be added globally in the archive.
Samples :
require_once('pclzip.lib.php');
$archive = new PclZip('archive.zip');
$v_list = $archive->add('file.txt,data/text.txt,folder/');
if ($v_list == 0) {
die("Error : ".$archive->errorInfo(true));
}
In this sample the files 'file.txt', 'data/text.txt' and all the content of the directory 'folder' are added in the archive.
require_once('pclzip.lib.php');
$archive = new PclZip('archive.zip');
$v_list = $archive->add('dev/file.txt,dev/text.txt',
PCLZIP_OPT_ADD_PATH, 'install',
PCLZIP_OPT_REMOVE_PATH, 'dev');
if ($v_list == 0) {
die("Error : ".$archive->errorInfo(true));
}In this sample the files 'dev/file.txt' and 'dev/text.txt' are added in the archive. However the path 'dev/' is removed and replaced by 'install/'. Therefore the files are stored with names 'install/file.txt' and 'install/text.txt'.
| [Back to Methods List] |




