PclZip est une librairie permettant
la manipulation des archives au format .zip (WinZip, PKZIP). Elle
permet de créer une archive, d'en lister le contenu, ainsi
que d'en extraire les fichiers et les dossiers. Pour chacune de
ces actions de base de nombreuses options sont possibles.
PhpConcept Library Zip défini
une classe d'objets appelée "PclZip" représentant
une archive au format .zip. Elle permet de gérer les attributs
propres à l'archive et d'offrir des méthodes d'accès
ou d'actions sur l'archive. Il est, par exemple, possible de :
Renommer
les fichiers avant de les archiver,
Archiver
tout un dossier, en retirant le préfixe du chemin du
dossier,
Ajouter
un commentaire à l'archive,
Appeler
une fonction avant et après l'archivage de chaque fichier
(pour traitement spécifiques),
Extraire
dans un dossier spécifique,
Extraire
uniquement certains fichiers (sélection par nom, index,
expression régulière),
Extraire
un fichier dans une chaine de caractères,
Extraire
un fichier directement dans la sortie standard (output).
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 :(pas traduit en français)
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 : (pas traduit en français)
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 : (pas traduit en français)
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 : (pas traduit en français)
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 : (pas traduit en français)
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 : (pas traduit en français)
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 : (pas traduit en français)
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 : (pas traduit en français)
*****
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 :
Correction
d'un bug lors de l'extraction en utilisant une fonction de call-back.
Version
1.3 :
Suppression
de la vérification de la double inclusion. Cela est maintenant
réalisé par les directives PHP include_once()
et require_once().
Changement
de la gestion des erreurs : l'usage d'une librairie externe
est supprimé.
-> Les anciennes fonctions PclError...() sont remplacées
par des méthodes internes équivalentes.
-> Il est cependant possible de changer la variable globale
PCLZIP_ERROR_EXTERNAL pour utiliser encore la librairie externe.
-> Utilisations de constantes nommée (define()) plutôt
que des valeurs entières. Cela aidera pour des évolutions
futures.
-> Apparition des méthodes internes errorCode(), errorName()
et errorInfo().
Suppression
des appels de fonctions par référence (non supporté
dans les dernières versions PHP)
Ajout de
l'appel des méthodes extract(), extractByIndex(), create()
et add() avec des iptions variables plutôt que des arguments
statiques.
Ajout de
la possibilité de supprimer tout le chemin d'accès
au fichier lors de l'archivage ou de l'extraction.
Cela est disponible pour extract(), extractByIndex(), create()
et add() en utilisant les nouveaux paramètres variables
(PCLZIP_OPT_REMOVE_ALL_PATH)
Ajout de
la possibilité de changer les attributs d'accès
(mode) d'un fichier après l'extraction en
utilisant le paramètre otpionnel (PCLZIP_OPT_SET_CHMOD)
Possibilité
de définir une fonction de "call-back" qui
sera appelée à l'ajout ou la suppression de chaque
fichier :
-> PCLZIP_CB_PRE_EXTRACT : sera appelé avant l'extraction
de chaque fichier. L'utilisateur peut donc agir sur l'extraction
individuelle d'un fichier en l'évitant ou en changeant
le nom de destination.
-> PCLZIP_CB_POST_EXTRACT : sera appelé après
l'extraction d'un fichier. Rien ne peut être fait sur
le processus d'extraction, mais il est possible d'agir sur le
fichier extrait.
-> PCLZIP_CB_PRE_ADD : sera appelé avant l'ajout de
chaque fichier. L'utilisateur peut donc agir sur l'ajout individuel
d'un fichier en l'évitant ou en changeant le nom d'archivage.
-> PCLZIP_CB_POST_ADD : sera appelé après l'ajout
d'un fichier. Rien ne peut être fait sur le processus
d'ajout, mais il est possible d'agir sur le fichier d'origine.
Deux nouveaux
status sont ajoutés au descriptif des fichiers : skipped
& filename_too_long
-> 'skipped' est utilisé lorsque le fichier a été
évité par un retour d'une fonction de call-back.
-> 'filename_too_long' est utilisé lorsqu'un fichier
a un nom trop long.
Ajout de
la fonction PclZipUtilPathInclusion(), qui vérifie si
un chemin fait parti d'un dossier ou non.
Ajout de
la vérification de la présence d'une archive avant
certaines actions (comme listContent() etc ..)
Ajout de
l'initialisation du champ "index" par défaut
à -1.
Version 1.2
:
Ajout de
la fonction merge(). Celle-ci permet d'ajouter à la fin
d'une archive zip l'ensemble du contenu d'une autre archive.
Aucun contrôle de duplicata de fichiers ou de date de
modifications n'est effectué.
Ajout de
la fonction duplicate(), qui permet de créer une archive
en dupliquant une archive existante.
Amélioration
de la lecture de la liste des fichiers d'une archive.
Version 1.1.2
:
Changement
de la license de PclZip. PclZip est maintenant distribué
sous license GNU / LGPL.
Ajout de
la configuration d'un dossier pour les fichiers temporaires.
Il est possible de configurer la variable PCLZIP_TEMPORARY_DIR.
Amélioration
de l'utilisation de la fonction rename(). Dans certains cas
(en particulier lors du changement de nom entre deux disques
différents) cette fonction échoue. Elle est alors
remplacée par copy() + unlink().
Correction
de bug : Les archives générées par PclZip
ne permettaient pas à WinZip de supprimer un seul fichier
ou d'ajouter des fichiers.
Version 1.1.1
:
Correction
de bug : Lorsque les fichiers archivés n'étaient
pas compressés, l'extraction pouvait entrainer une erreur
fatale de php.exe
Version 1.1
:
Ajout de
la fonction PclZip::Add()
Ajout de
la fonction PclZip::ExtractByIndex()
Ajout de
la fonction PclZip::DeleteByIndex()
Ajout d'un
test sur la présence de la zlib (librairie gz)
Correction
de bug : Dans certains cas, lorsque l'on indiquait un chemin
complet depuis la racine l'archive de se faisait pas.
Version 1.0.1
:
Correction
de bug : Les fichiers de taille supérieur à PCLZIP_READ_BLOCK_SIZE
(par défaut 1024) n'étaient pas compressés
correctement.
Q1 : Lors
de la création d'une archive avec PclZip, le script s'arrête
en laissant une archive vide, que se passe-t-il ?
Ce comportement
a été rencontré lorsque l'extension zlib
n'a pas été installé avec PHP. PclZip nécessite
l'utilisation de la compression apportée par zlib. Dans
les versions futures (1.1+) de PclZip un test systématique
de la présence de la zlib sera effectué.
Q2 : Je
n'arrive pas à ouvrir, avec WinZip, une archive zip créée
par PclZip !
Il semble
en effet que WinZip 6.0 (et surement les versions antérieures)
ne puisse pas lire les archives zip créées par
PclZip. Cependant avec la dernière version WinZip 8.0
cela fonctionne sans soucis. Il est aussi à noter que
les archives créées par WinZip 6.0 sont lisible
par PclZip.