In PHP, zip_entry_read() reads up to a given number of bytes from an opened ZIP entry.
It is deprecated as of PHP 8.0. With ZipArchive, use getFromName() or getFromIndex() for a whole entry, or getStream() with fread() to read it in chunks.
Syntax
Call zip_entry_read() with the values you need. Start with this line.
Deprecated: reads the whole entry by asking for its full size.
$zip->getFromName('hello.txt', 5)
Modern ZipArchive: reads only the first 5 bytes. Leave the length out to read everything.
zip_entry_read() is deprecated in PHP 8.0. Remember that it read only $len bytes at a time, so large files needed a loop. ZipArchive::getFromName() returns everything at once when you omit the length.
Library declarations
PHP
zip_entry_read(resource $zip_entry, int $len = 1024): string|false
Parameters
Parameter
Description
zip_entry
Required. A directory entry resource that was opened with zip_entry_open().
len
Optional. How many bytes to read. The default is 1024.
Return Value
Return Value
Description
string
The data that was read. It can be shorter than len near the end of the entry.
false
The data could not be read.
PHP Examples
Example 1 — Read a Whole Entry
Read hello.txt into a string with ZipArchive. The old zip_entry_read() call is shown as a comment.