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.
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).
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.
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.
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 :