PHP Zip Functions

Beginner
4 min read
Updated: Nov 2026
10 function guides
Function index

About This Index

This page is the PHP Zip Functions index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs for one procedural Zip function.

Learn how to create, list, read, and extract archives with ZipArchive on /php/zip. Use this page when you meet a legacy function such as zip_open(), zip_read(), or zip_entry_read() in older code.

Prefer ZipArchive.

Every function on this page is deprecated since PHP 8.0. Do not use them in new code. The ZipArchive class is the maintained API, it can also create and change archives, and each procedural function has a matching method. Read the PHP Zip page first.

Read-only and handle based.

The procedural API can only read archives. You open the archive to get a handle, call zip_read() to get an entry, and then open, read, and close that entry. There is no way to add files or save changes.

How to Call a PHP Zip Function

Every function is global—call it directly. The legacy loop below is what you will see in old scripts, followed by the ZipArchive version to use today:

PHP
// Legacy procedural API (deprecated since PHP 8.0)
$zip = zip_open('files.zip');                          // resource|int
if (is_resource($zip)) {
    while ($entry = zip_read($zip)) {                  // resource|false
        echo zip_entry_name($entry), PHP_EOL;          // string
        echo zip_entry_filesize($entry), PHP_EOL;      // int
        echo zip_entry_compressedsize($entry), PHP_EOL; // int
        echo zip_entry_compressionmethod($entry), PHP_EOL; // string, e.g. deflated

        if (zip_entry_open($zip, $entry, 'r')) {       // bool
            $data = zip_entry_read($entry, zip_entry_filesize($entry)); // string|false
            zip_entry_close($entry);                   // bool
        }
    }
    zip_close($zip);                                   // void
}

// Preferred: ZipArchive
$za = new ZipArchive();
if ($za->open('files.zip') === true) {
    for ($i = 0; $i < $za->numFiles; $i++) {
        $st = $za->statIndex($i);                      // name, size, comp_size, comp_method
        $data = $za->getFromIndex($i);                 // string|false
    }
    $za->close();
}

PHP Zip Functions Table

All function guides in this PHP tutorial series (10 tutorials in 3 categories). All of them are deprecated since PHP 8.0, so prefer ZipArchive.

Open & close archive

3 functions

Open a ZIP file, step through its entries, and close it. These functions are deprecated since PHP 8.0; ZipArchive::open(), a for loop and ZipArchive::close() replace them.

FunctionDescriptionTutorial
zip_open()Open a ZIP file for reading and return a handle.Try it
zip_close()Close a ZIP archive handle.Try it
zip_read()Read the next entry in the archive.Try it

Entry open, read & close

3 functions

Open one entry, read its data in pieces, and close it. ZipArchive::getFromName() and getFromIndex() do all three steps in one call.

FunctionDescriptionTutorial
zip_entry_open()Open an archive entry so its data can be read.Try it
zip_entry_read()Read a number of bytes from an open entry.Try it
zip_entry_close()Close an entry that was opened with zip_entry_open().Try it

Entry info

4 functions

Get the name, sizes, and compression method of an entry. ZipArchive::statIndex() returns all of this in one array.

FunctionDescriptionTutorial
zip_entry_name()Get the name of an archive entry.Try it
zip_entry_filesize()Get the original (uncompressed) size of an entry.Try it
zip_entry_compressedsize()Get the compressed size of an entry.Try it
zip_entry_compressionmethod()Get the compression method used for an entry.Try it

Frequently Asked Questions

They are the procedural zip_* and zip_entry_* functions of the zip extension: zip_open(), zip_read() and zip_close() to walk an archive, zip_entry_open(), zip_entry_read() and zip_entry_close() to read an entry, and zip_entry_name(), zip_entry_filesize(), zip_entry_compressedsize() and zip_entry_compressionmethod() to get facts about an entry. They can only read archives.
Yes. The whole procedural Zip API is deprecated since PHP 8.0. The functions still run, but they raise a deprecation notice and they may be removed in a future major version. Use the ZipArchive class for all new code.
Create a ZipArchive object, call open() and check that it returns true, then loop from 0 to numFiles - 1. Use getNameIndex() or statIndex() for the entry name and sizes, getFromName() or getFromIndex() for the content, and extractTo() to unpack everything. See the PHP Zip page for working examples.
The PHP Zip page teaches the ideas with ZipArchive: creating an archive, listing entries, reading files, extracting, and enabling the extension. This index lists a guide for every legacy function, so you can understand and migrate older code that still uses zip_open() and zip_read().
zip_open() maps to ZipArchive::open(), zip_close() to close(), and the zip_read() loop to a for loop over numFiles. zip_entry_name() maps to getNameIndex(), zip_entry_filesize() and zip_entry_compressedsize() to the size and comp_size keys of statIndex(), and the open, read and close trio to getFromName() or getFromIndex().
The zip extension may be disabled in your PHP build. Run var_dump(extension_loaded('zip')); to check. If it prints false, install the zip package for your PHP version (often php-zip) or enable extension=zip in php.ini, then restart PHP.

Start with zip_close()

Open the next guide—syntax, examples, and FAQs.

zip_close() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful