PhpConcept
 
 

PhpConcept Library Zip
PclZip 2.8.2

 
 

Overview - User Guide - Downloads - What's New - FAQ

 
 
Overview
 
 

 

PclZip library offers compression and extraction functions for Zip formatted archives (WinZip, PKZIP).

PclZip gives you the ability to manipulate zip formatted arhives. You can create an archive, list the content and extract all its content in the file system.

PclZip defines an object class which represent a Zip Archive. This class manages the archive properties and offers access method and actions on the archive.

 

 
     
 

Overview - User Guide - Downloads - What's New - FAQ

 
 
Downloads
 
 
     
  PclZip  
 
Release 2.8.2   Taille   zip   GNU Tar  
    Library 2.8.2
  - ko   pclzip-2-8-2.zip   pclzip-2-8-2.tgz  
    Library 2.8.2 With Trace
  - ko   pclzip-with-trace-2-8-2.zip   pclzip-with-trace-2-8-2.tgz  
Release 2.8.1   Taille   zip   GNU Tar  
    Library 2.8.1
  - ko   pclzip-2-8-1.zip   pclzip-2-8-1.tgz  
    Library 2.8.1 With Trace
  - ko   pclzip-with-trace-2-8-1.zip   pclzip-with-trace-2-8-1.tgz  
Release 2.8   Taille   zip   GNU Tar  
    Library 2.8
  - ko   pclzip-2-8.zip   pclzip-2-8.tgz  
    Library 2.8 With Trace
  - ko   pclzip-with-trace-2-8.zip   pclzip-with-trace-2-8.tgz  
Release 2.7   Taille   zip   GNU Tar  
    Library 2.7
  - ko   pclzip-2-7.zip   pclzip-2-7.tgz  
    Library 2.7 With Trace
  - ko   pclzip-with-trace-2-7.zip   pclzip-with-trace-2-7.tgz  
Release 2.6   Taille   zip   GNU Tar  
    Library 2.6
  - ko   pclzip-2-6.zip   pclzip-2-6.tgz  
    Library 2.6 With Trace
  - ko   pclzip-with-trace-2-6.zip   pclzip-with-trace-2-6.tgz  
Release 2.5   Taille   zip   GNU Tar  
    Library 2.5
  - ko   pclzip-2-5.zip   pclzip-2-5.tgz  
    Library 2.5 With Trace
  - ko   pclzip-with-trace-2-5.zip   pclzip-with-trace-2-5.tgz  
Release 2.4   Size   zip   GNU Tar  
    Release 2.4
  - ko   pclzip-2-4.zip   pclzip-2-4.tgz  
    Release 2.4 With Trace
  - ko   pclzip-with-trace-2-4.zip   pclzip-with-trace-2-4.tgz  
Release 2.3   Size   zip   GNU Tar  
    Release 2.3
  261 ko   pclzip-2-3.zip   pclzip-2-3.tgz  
    Release 2.3 With Trace
  271 ko   pclzip-with-trace-2-3.zip   pclzip-with-trace-2-3.tgz  
Release 2.2   Size   zip   GNU Tar  
    Release 2.2
  261 ko   pclzip-2-2.zip   pclzip-2-2.tgz  
    Release 2.2 With Trace
  271 ko   pclzip-with-trace-2-2.zip   pclzip-with-trace-2-2.tgz  
Release 2.1   Size   zip   GNU Tar  
    Release 2.1
  246 ko   pclzip-2-1.zip   pclzip-2-1.tgz  
    Release 2.1 With Trace
  257 ko   pclzip-with-trace-2-1.zip   pclzip-with-trace-2-1.tgz  
Release 2.0   Size   zip   GNU Tar  
    Release 2.0
  234 ko   pclzip-2-0.zip   pclzip-2-0.tgz  
    Release 2.0 With Trace
  246 ko   pclzip-with-trace-2-0.zip   pclzip-with-trace-2-0.tgz  
Release 1.3.1   Size   zip   GNU Tar  
    Release
  221 ko   pclzip-1-3-1.zip   pclzip-1-3-1.tgz  
    Release With Trace
  232 ko   pclzip-with-trace-1-3-1.zip   pclzip-with-trace-1-3-1.tgz  
Release 1.3   Size   zip   GNU Tar  
    Release
  219 ko   pclzip-1-3.zip   pclzip-1-3.tgz  
    Release With Trace
  321 ko   pclzip-with-trace-1-3.zip   pclzip-with-trace-1-3.tgz  
Release 1.2   Size   zip   GNU Tar  
    PHP4 Version
  301 ko   pclzip-1-2.zip   pclzip-1-2.tgz  
Release 1.1.2   Size   zip   GNU Tar  
    PHP3 Version
  169 ko   pclzip-1-1-2-php3.zip   pclzip-1-1-2-php3.tgz  
    PHP4 Version
  169 ko   pclzip-1-1-2-php4.zip   pclzip-1-1-2-php4.tgz  
Release 1.1.1   Size   zip   GNU Tar  
    PHP3 Version
  140 ko   pclzip-1-1-1-php3.zip   pclzip-1-1-1-php3.tgz  
    PHP4 Version
  140 ko   pclzip-1-0-1-php4.zip   pclzip-1-1-1-php4.tgz  
Release 1.1   Size   zip   GNU Tar  
    PHP3 Version
  Deprecated  
    PHP4 Version
  Deprecated  
Release 1.0.1   Size   zip   GNU Tar  
    PHP3 Version
  102 ko   pclzip-1-0-1-php3.zip   pclzip-1-0-1-php3.tgz  
    PHP4 Version
  102 ko   pclzip-1-0-1-php4.zip   pclzip-1-0-1-php4.tgz  
Release 1.0   Size   zip   GNU Tar  
    PHP3 Version
  Deprecated  
    PHP4 Version
  Deprecated  
 
     
 
     
 

Overview - User Guide - Downloads - What's New - FAQ

 
 
What's New
 
 

 

Version 2.8.2 :

  • PCLZIP_CB_PRE_EXTRACT and PCLZIP_CB_POST_EXTRACT are now supported with extraction as a string (PCLZIP_OPT_EXTRACT_AS_STRING). The string can also be modified in the post-extract call back.
  • **Bugs correction :
  • PCLZIP_OPT_REMOVE_ALL_PATH was not working correctly
  • Remove use of eval() and do direct call to callback functions
  • Correct support of 64bits systems (Thanks to WordPress team) .

Version 2.8.1 :

  • Move option PCLZIP_OPT_BY_EREG to PCLZIP_OPT_BY_PREG because ereg() is deprecated in PHP 5.3. When using option PCLZIP_OPT_BY_EREG, PclZip will automatically replace it by PCLZIP_OPT_BY_PREG.

Version 2.8 :

  • Improve extraction of zip archive for large files by using temporary files This feature is working like the one defined in r2.7. Options are renamed : PCLZIP_OPT_TEMP_FILE_ON, PCLZIP_OPT_TEMP_FILE_OFF, PCLZIP_OPT_TEMP_FILE_THRESHOLD
  • Add a ratio constant PCLZIP_TEMPORARY_FILE_RATIO to configure the auto sense of temporary file use.
  • Bug correction : Reduce filepath in returned file list to remove ennoying './/' preambule in file path.

Version 2.7 :

  • Improve creation of zip archive for large files : PclZip will now autosense the configured memory and use temporary files when large file is suspected.
    This feature can also ne triggered by manual options in create() and add() methods.
    'PCLZIP_OPT_ADD_TEMP_FILE_ON' force the use of temporary files, 'PCLZIP_OPT_ADD_TEMP_FILE_OFF' disable the autosense technic, 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD' allow for configuration of a size threshold to use temporary files.
    Using "temporary files" rather than "memory" might take more time, but might give the ability to zip very large files : Tested on my win laptop with a 88Mo file :
    Zip "in-memory" : 18sec (max_execution_time=30, memory_limit=180Mo)
    Zip "tmporary-files" : 23sec (max_execution_time=30, memory_limit=30Mo)
  • Replace use of mktime() by time() to limit the E_STRICT error messages.
  • Bug correction : When adding files with full windows path (drive letter) PclZip is now working. Before, if the drive letter is not the default path, PclZip was not able to add the file.

Version 2.6 :

  • Code optimisation
  • New attributes PCLZIP_ATT_FILE_COMMENT gives the ability to add a comment for a specific file. (Don't really know if this is usefull)
  • New attribute PCLZIP_ATT_FILE_CONTENT gives the ability to add a string as a file.
  • New attribute PCLZIP_ATT_FILE_MTIME modify the timestamp associated with a file.
  • Correct a bug. Files archived with a timestamp with 0h0m0s were extracted with current time
  • Add CRC value in the informations returned back for each file after an action.
  • Add missing closedir() statement.
  • When adding a folder, and removing the path of this folder, files were incorrectly added with a '/' at the beginning. Which means files are related to root in unix systems. Corrected.
  • Add conditional if before constant definition. This will allow users to redefine constants without changing the file, and then improve upgrade of pclzip code for new versions.

Version 2.5 :

  • Introduce the ability to add file/folder with individual properties (file descriptor).
    This gives for example the ability to change the filename of a zipped file.
    • Able to add files individually
    • Able to change full name
    • Able to change short name
    • Compatible with global options
  • New attributes : PCLZIP_ATT_FILE_NAME, PCLZIP_ATT_FILE_NEW_SHORT_NAME, PCLZIP_ATT_FILE_NEW_FULL_NAME
  • New error code : PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE
  • Add a security control feature. PclZip can extract any file in any folder of a system. People may use this to upload a zip file and try to override a system file. The PCLZIP_OPT_EXTRACT_DIR_RESTRICTION will give the ability to forgive any directory transversal behavior.
  • New PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : check extraction path
  • New error code : PCLZIP_ERR_DIRECTORY_RESTRICTION
  • Modification in PclZipUtilPathInclusion() : dir and path beginning with ./ will be prepend by current path (getcwd())

Version 2.4 :

  • Code improvment : try to speed up the code by removing unusefull call to pack()
  • Correct bug in delete() : delete() should be called with no argument. This was not the case in 2.3. This is corrected in 2.4.
  • Correct a bug in path_inclusion function. When the path has several '../../', the result was bad.
  • Add a check for magic_quotes_runtime configuration. If enabled, PclZip will disable it while working and det it back to its original value.
    This resolve a lots of bad formated archive errors.
  • Bug correction : PclZip now correctly unzip file in some specific situation, when compressed content has same size as uncompressed content.
  • Bug correction : When selecting option 'PCLZIP_OPT_REMOVE_ALL_PATH', directories are not any more created.
  • Code improvment : correct unclosed opendir(), better handling of . and .. in loops.

Version 2.3 :

  • Correct a bug with PHP5 : affecting the value 0xFE49FFE0 to a variable does not
    give the same result in PHP4 and PHP5 ....

Version 2.2 :

  • Try development of PCLZIP_OPT_CRYPT ..... However this becomes to a stop. To crypt/decrypt I need to multiply 2 long integers, the result (greater than a long) is not supported by PHP. Even the use of bcmath functions does not help. I did not find yet a solution ...;
  • Add missing '/' at end of directory entries
  • Check is a file is encrypted or not. Returns status 'unsupported_encryption' and/or error code PCLZIP_ERR_UNSUPPORTED_ENCRYPTION.
  • Corrected : Bad "version need to extract" field in local file header
  • Add private method privCheckFileHeaders() in order to check local and central file headers. PclZip is now supporting purpose bit flag bit 3. Purpose bit flag bit 3 gives the ability to have a local file header without size, compressed size and crc filled.
  • Add a generic status 'error' for file status - Add control of compression type. PclZip only support deflate compression method. Before v2.2, PclZip does not check the compression method used in an archive while extracting. With v2.2 PclZip returns a new error status for a file using an unsupported compression method. New status is "unsupported_compression". New error code is PCLZIP_ERR_UNSUPPORTED_COMPRESSION.
  • Add optional attribute PCLZIP_OPT_STOP_ON_ERROR. This will stop the extract of files when errors like 'a folder with same name exists' or 'a newer file exists' or 'a write protected file' exists, rather than set a status for the concerning file and resume the extract of the zip.
  • Add optional attribute PCLZIP_OPT_REPLACE_NEWER. This will force, during an extract' the replacement of the file, even if a newer version of the file exists. Note that today if a file with the same name already exists but is older it will be replaced by the extracted one.
  • Improve PclZipUtilOption()
  • Support of zip archive with trailing bytes. Before 2.2, PclZip checks that the central directory structure is the last data in the archive. Crypt encryption/decryption of zip archive put trailing 0 bytes after decryption. PclZip is now supporting this.

Version 2.1 :

  • Add the ability to extract a file (or several files) directly in the standard output.
    This is done by the new parameter PCLZIP_OPT_EXTRACT_IN_OUTPUT with method extract().
  • Add support for parameters PCLZIP_OPT_COMMENT, PCLZIP_OPT_ADD_COMMENT,
    PCLZIP_OPT_PREPEND_COMMENT. This will create, replace, add, or prepend comments
    in the zip archive.
  • Add the ability to abort the extraction by using a user callback function.
    The user can now return the value '2' in its callback which indicates to stop the
    extraction. For a pre call-back extract is stopped before the extration of the current
    file. For a post call back, the extraction is stopped after.
  • When merging two archives, the comments are not any more lost, but merged, with a
    blank space separator.
  • Corrected bug : Files are not deleted when all files are asked to be deleted.
  • Corrected bug : Folders with name '0' made PclZip to abort the create or add feature.

Version 2.0 :

  • ***** Warning : Some new features may break the backward compatibility for your scripts.
    Please carefully read the readme file.
  • Add the ability to delete by Index, name and regular expression. This feature is
    performed by the method delete(), which uses the optional parameters
    PCLZIP_OPT_BY_INDEX, PCLZIP_OPT_BY_NAME, PCLZIP_OPT_BY_EREG or PCLZIP_OPT_BY_PREG.
  • Add the ability to extract by regular expression. To extract by regexp you must use the method
    extract(), with the option PCLZIP_OPT_BY_EREG or PCLZIP_OPT_BY_PREG
    (depending if you want to use ereg() or preg_match() syntax) followed by the
    regular expression pattern.
  • Add the ability to extract by index, directly with the extract() method. This is a
    code improvment of the extractByIndex() method.
  • Add the ability to extract by name. To extract by name you must use the method
    extract(), with the option PCLZIP_OPT_BY_NAME followed by the filename to
    extract or an array of filenames to extract. To extract all a folder, use the folder
    name rather than the filename with a '/' at the end.
  • Add the ability to add files without compression. This is done with a new attribute
    which is PCLZIP_OPT_NO_COMPRESSION.
  • Add the attribute PCLZIP_OPT_EXTRACT_AS_STRING, which allow to extract a file directly
    in a string without using any file (or temporary file).
  • Add constant PCLZIP_SEPARATOR for static configuration of filename separators in a single string.
    The default separator is now a comma (,) and not any more a blank space.
    THIS BREAK THE BACKWARD COMPATIBILITY : Please check if this may have an impact with
    your script.
  • Improve algorythm performance by removing the use of temporary files when adding or
    extracting files in an archive.
  • Add (correct) detection of empty filename zipping. This can occurs when the removed
    path is the same
    as a zipped dir. The dir is not zipped (['status'] = filtered), only its content.
  • Add better support for windows paths (thanks for help from manus@manusfreedom.com).
  • Corrected bug : When the archive file already exists with size=0, the add() method
    fails. Corrected in 2.0.
  • Remove the use of OS_WINDOWS constant. Use php_uname() function rather.
  • Control the order of index ranges in extract by index feature.
  • Change the internal management of folders (better handling of internal flag).

Version 1.3.1 :

  • Correcting a bug which occurs while doing extraction with call-back functions.

Version 1.3 :

  • Removing the double include check. This is now done by include_once() and require_once()
    PHP directives.
  • Changing the error handling mecanism : Remove the use of an external error library.
    The former PclError...() functions are replaced by internal equivalent methods.
    By changing the environment variable PCLZIP_ERROR_EXTERNAL you can still use the former library.
    Introducing the use of constants for error codes rather than integer values. This will help
    in futur improvment.
    Introduction of error handling functions like errorCode(), errorName() and errorInfo().
  • Remove the deprecated use of calling function with arguments passed by reference.
  • Add the calling of extract(), extractByIndex(), create() and add() functions
    with variable options rather than fixed arguments.
  • Add the ability to remove all the file path while extracting or adding,
    without any need to specify the path to remove.
    This is available for extract(), extractByIndex(), create() and add() functionS by using
    the new variable options parameters :
    PCLZIP_OPT_REMOVE_ALL_PATH : by indicating this option while calling the fct.
  • Ability to change the mode of a file after the extraction (chmod()).
    This is available for extract() and extractByIndex() functionS by using
    the new variable options parameters.
    PCLZIP_OPT_SET_CHMOD : by setting the value of this option.
  • Ability to definition call-back options. These call-back will be called during the adding,
    or the extracting of file (extract(), extractByIndex(), create() and add() functions) :
    - PCLZIP_CB_PRE_EXTRACT : will be called before each extraction of a file. The user
    can trigerred the change the filename of the extracted file. The user can triggered the
    skip of the extraction. This is adding a 'skipped' status in the file list result value.
    - PCLZIP_CB_POST_EXTRACT : will be called after each extraction of a file.
    Nothing can be triggered from that point.
    - PCLZIP_CB_PRE_ADD : will be called before each add of a file. The user
    can trigerred the change the stored filename of the added file. The user can triggered the
    skip of the add. This is adding a 'skipped' status in the file list result value.
    - PCLZIP_CB_POST_ADD : will be called after each add of a file.
    Nothing can be triggered from that point.
  • Two status are added in the file list returned as function result : skipped & filename_too_long
    'skipped' is used when a call-back function ask for skipping the file.
    'filename_too_long' is used while adding a file with a too long filename to archive (the file is
    not added)
  • Adding the function PclZipUtilPathInclusion(), that check the inclusion of a path into
    a directory.
  • Add a check of the presence of the archive file before some actions (like list, ...)
  • Add the initialisation of field "index" in header array. This means that by
    default index will be -1 when not explicitly set by the methods.

Version 1.2 :

  • Adding a duplicate function.
  • Adding a merge function. The merge function is a "quick merge" function, it just append the content of an archive at the end of the first one. There is no check for duplicate files or more recent files.
  • Improve the search of the central directory end.

Version 1.1.2 :

  • Changing the license of PclZip. PclZip is now released under the GNU / LGPL license.
  • Adding the optional support of a static temporary directory. You will need to configure
    the constant PCLZIP_TEMPORARY_DIR if you want to use this feature.
  • Improving the rename() function. In some cases rename() does not work (different
    Filesystems), so it will be replaced by a copy() + unlink() functions.
  • Bug correction : Winzip is unable to delete or add new files in a PclZip created archives

Version 1.1.1 :

  • Bug correction : When archived file is not compressed (0% compression), the extract method may fail.

Version 1.1 :

  • Adding function PclZip::Add()
  • Adding function PclZip::ExtractByIndex()
  • Adding function PclZip::DeleteByIndex()
  • Bug correction : In certain circonstancies, while archiving a file with the full path from the root, the archive is not done correctly.

Version 1.0.1 :

  • Bug correction : Error while compressing files greater than PCLZIP_READ_BLOCK_SIZE (default=1024).
 
     
 

Overview - User Guide - Downloads - What's New - FAQ

 
 
FAQ
 
 

 

F.A.Q. :

Q1 : While creating an archive with PclZip, the script terminates with an empty created zip archive, why ?

The behavior was encounter while the zlib extension is not enabled with the PHP installation. PclZip uses the compression functions from the zlib. In next releases of PclZip (1.1+) a systematic control of the zlib presence will be done.

(Link to FAQ-01)

Q2 : I can not open with WinZip a zip archive created by PclZip !

WinZip 6.0 (and earlier) is not able to open zip archives created by PclZip. However last version of WinZip (v8.0) is working correctly with PclZip generated archives. Please note also that archives created by PclZip can be read by WinZip 6.0.

(Link to FAQ-02)

Q3 : While extracting (creating) a zip with PclZip the PHP script hang before the end of the script, without any error message ...

PclZip depend on two PHP configuration parameters for its performance :
PclZip is using in memory compression/decompression of files in order to limit the usage of temporary files. This technic depends on the memory allocated to a PHP thread by the hosting server. If you are zipping a very large file, a large amount of memory will be needed, if you are zipping lots of small files it should be ok. The allocated memory for PHP can be configured by changing the "memory_limit" parameter in the php.ini file (see for more details). The default value is 8M.
When you extract or create a very fat zip (big zip or zip with many small files), PHP needs lots of time to process all the archive. The execution time allocated to a PHP thread is configured in the php.ini file (see for more details). The default is 30 secondes.

Q4 : While extracting a zip with PclZip I see nothing (no extracted file, no error) ...

PclZip support an error mechanism described in the user manual (see ). You must check for error after calling a PclZip function.

However the initial implementation of PclZip support a kind of minor "error recovery" mecanism. The idea is that the script will stop only if it can not recover from an error. When extracting an archive if one file can not be extracted, the script does not stop, but resume the action and tries to extract the other files. In order to check which file was extracted or not, and why some files were not extracted (bad access rights, already existing files, directories with same names, ...) you need to study the resulting array of the extract action.
If you want to see how it works, run this sample code :

<?php
  
require_once('pclzip.lib.php');
  
$archive = new PclZip('archive.zip');
  if ((
$v_result_list $archive->extract()) == 0) {
    die(
"Error : ".$archive->errorInfo(true));
  }
  echo 
"<pre>";
  
var_dump($v_result_list);
  echo 
"</pre>";
?>

Since PclZip release 2.2, you have the ability to stop the extraction at the first "minor" error. To do that you need to use the optional parameter PCLZIP_OPT_STOP_ON_ERROR :

<?php
  
require_once('pclzip.lib.php');
  
$archive = new PclZip('archive.zip');
  if ((
$v_result_list $archive->extract(PCLZIP_OPT_STOP_ON_ERROR)) == 0) {
    die(
"Error : ".$archive->errorInfo(true));
  }
  echo 
"<pre>";
  
var_dump($v_result_list);
  echo 
"</pre>";
?>

(Link to FAQ-04)

Q5 : How can I create a zip file with the current directory and all its content recursively ?

PclZip does not directly support the add of folder "./". To do this you will have to use a trick :

<?php
  
require_once('pclzip.lib.php');
  
$archive = new PclZip('archive.zip');
  
$v_dir getcwd(); // or dirname(__FILE__);
  
$v_remove $v_dir;
  
// To support windows and the C: root you need to add the 
  // following 3 lines, should be ignored on linux
  
if (substr($v_dir1,1) == ':') {
    
$v_remove substr($v_dir2);
  }
  
$v_list $archive->create($v_dirPCLZIP_OPT_REMOVE_PATH$v_remove);
  if (
$v_list == 0) {
    die(
"Error : ".$archive->errorInfo(true));
  }
?>

(Link to FAQ-05)

 

 
     
 

Overview - User Guide - Downloads - What's New - FAQ

 

Member login - Stats
Copyright 2003 - PhpConcept

Powered by PcWeb