PhpConcept

Developers Tools

  • Increase font size
  • Default font size
  • Decrease font size
Home PclZip User Guide

PclZip User Guide - PclZip::create

Print PDF

Method PclZip::create

Overview

This method creates PKZIP archives with the specified files.

Synopsis

PclZip::create($filelist, [optional arguments])

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_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 porperties. (See "Returned values")

Description

This method creates an archhive with all the files and folders indicated in the argument paramètre $filelist. When the filename is the name of a folder, all the files and subdirs of the folder are added, the filesystem structure is memorized.
The optional arguments gives the ability to archive files with a different path namethan the realone. This allow to put the script somewhere in a private path, and archive files without showing the path between the scriptand the files.
This can be used also to prepare a 'default' extraction path of the archived files.

Samples

  include_once('pclzip.lib.php');
  
$archive = new PclZip('archive.zip');
  
$v_list $archive->create('file.txt,data/text.txt,folder');
  if (
$v_list == 0) {
    die(
"Error : ".$archive->errorInfo(true));
  }
 

In this sample the PKZIP archive 'archive.zip' is created. The files file.txt and data/text.txt are added. All the folder 'folder' is added (its files and recursively all the subdirs)

 
  
include_once('pclzip.lib.php');
  
$archive = new PclZip('archive.zip');
  
$v_list $archive->create('data/file.txt,data/text.txt',
                             
PCLZIP_OPT_REMOVE_PATH'data',
                             
PCLZIP_OPT_ADD_PATH'install');
  if (
$v_list == 0) {
    die(
"Error : ".$archive->errorInfo(true));
  }

in this sample the files 'file.txt' and 'text.txt', which are locally in the folder 'data', are added in the archive without the path 'data', but with the path 'install'. They are stored with filenames 'install/file.txt' and 'install/text.txt'.

See also

PclZip(), add(), extract(), delete()

 

[Back to Methods List]

 

Last Updated on Thursday, 17 December 2009 10:44