For memory

  • PHP 7.2 to 7.4 provide version 1.15
  • PHP 8.0 will provide version 1.18
  • The extension from PECL provides the latest versions on all PHP versions and is also used on some Linux distributions  (Fedora, RHEL and CentOS 8) and of course, for users of my repository.

This extension uses the libzip library which has received a lot of enhancements in recent versions.

So, I thought it is useful to refresh this extension, to take benefit of new features.

Version 1.16

Store of the modification time of a file using the ZipArchive::setMtimeIndex and ZipArchive::setMtimeName methods. Mostly useful when content is directly added (not from a file).

Support of XZ compression. This requires version ≥ 1.6 of the library with the proper build option enabled.

Version 1.17

Support of save progression, using a callback: ZipArchive::registerProgressCallback. This requires version ≥ 1.3 of the library.

Support of save cancellation, using a callback: ZipArchive::registerCancelCallback. This requires version ≥ 1.6 of the library.

An archive can now be open in read only mode. This requires version ≥ 1.0 of the library.

Version 1.18

New flags parameter for ZipArchive::addEmptyDir, ZipArchive::addFile and ZipArchive::addFromString methods. This option allows managing character encoding of the entry names and replacement of existing entries.

New flags in the options array passed to ZipArchive::addGlob and ZipArchive::addPattern methods.

New ZipArchive::replaceFile method which allows replacing an entry content, without changing its name.

New lastId property which gives the index of the last added entry, and thus avoids a search for additional actions (comment, attributes, ...).

The status, statusSys properties and the ZipArchive::getStatusString method are now available after the archive is closed, allowing checking the reason for some possible error.


I think that all these changes bring meaningful improvement to the extension features.

A quite complete example is available in the sources repository: zipcmd.php.

Documentation is already updated.


I will continue to follow closely changes in the libzip library so we can quickly take the benefits of new features.

I'm waiting for upstream feedback on change proposal which will allow knowing which optional features are available (encryption, compression).

I'm also thinking about file permissions storage and restoration, sadly current API doesn't seem designed for this, especially for directories. I'm also afraid of possible security issues using specially crafted archives. This management still quite easy using the ZipArchive::setExternalAttributesName and  ZipArchive::getExternalAttributesIndex methods(see the code example).