PhpZip

A pure-PHP library for creating, reading, and modifying ZIP archives without the zip extension.

Library
Composer
v4.0.2
501stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
42/100Fair
Development Activity0
Maintenance20
Community68
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture82
Code Quality80
Innovation74
Learning Curve78

PhpZip is a PHP library for extended work with ZIP archives, implemented entirely in pure PHP so it does not require the php-zip extension or the built-in \ZipArchive class. It lets you open, extract, create, and modify ZIP files, with support for archive and per-entry comments, detailed entry metadata, and multiple output targets.

The library supports Stored, Deflate, and BZIP2 compression, ZIP64 for archives larger than 4 GB or with more than 65,535 entries, and password-based encryption. Archives can be saved to a file, streamed to the browser, or returned as an in-memory string, making it flexible for both server-side storage and on-the-fly downloads.

What You Get

  • A fluent ZipFile API for opening, extracting, creating, and modifying ZIP archives
  • Pure-PHP implementation that does not depend on the php-zip extension or \ZipArchive
  • Support for Stored, Deflate, and BZIP2 compression methods
  • ZIP64 support for archives over 4 GB or with more than 65,535 entries
  • Password encryption plus archive and per-entry comment handling

Common Use Cases

  • Generating a ZIP download on the fly and streaming it directly to the browser
  • Extracting uploaded ZIP archives on servers without the native zip extension
  • Modifying an existing archive by adding, renaming, or deleting entries
  • Building password-protected ZIP files for secure distribution

Under The Hood

Architecture - The public surface is the single ZipFile class (src/ZipFile.php), which orchestrates lower-level packages: Model holds entry and central-directory representations, IO handles reading and writing streams, Constants defines compression and encryption methods, and Util provides byte and CRC helpers. Exception classes surface archive errors. This layering keeps the fluent API thin while the parsing and serialization of the ZIP format live in dedicated model and IO components.

Tech Stack - Pure PHP targeting 7.4 and 8.x, distributed as nelexa/zip under PSR-4 autoloading. BZIP2 support is optional via the php-bz2 extension, and the library deliberately avoids the php-zip extension. Tooling includes PHPUnit for tests, Psalm for static analysis, and a bootstrap file for autoloading in tests.

Code Quality - The code is organized into focused namespaces with a dedicated test suite (40+ test files) and Psalm static analysis configured. Compression, ZIP64, and encryption paths each have clear model support, and exceptions are typed. Recent maintenance activity is low, but the codebase is mature and coherent.

API Design - The ZipFile API is fluent and approachable: methods like addFile(), addFromString(), setPassword(), and saveAsFile()/outputAsAttachment() chain naturally, and the README documents each operation extensively. The single-entry-point design keeps the learning curve gentle for common create/extract/modify tasks.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search