PHP zip_entry_read() Function

❮ PHP Zip Reference

Example

Open a ZIP file archive, open directory entry for reading, and read from the open directory entry:

<?php
$zip = zip_open("test.zip");

if ($zip) {
  while ($zip_entry = zip_read($zip)) {
    echo "<p>Name: " . zip_entry_name($zip_entry) . "<br>";
    // Open directory entry for reading
    if (zip_entry_open($zip, $zip_entry)) {
      echo "File Contents:<br>";
      // Read open directory entry
      $contents = zip_entry_read($zip_entry);
      echo "$contents<br>";
      zip_entry_close($zip_entry);
    }
  echo "</p>";
  }
zip_close($zip);
}
?>

The output of the code depends on the contents of the ZIP archive:

Name: ziptest.txt
File Contents:
Hello World! This is a test.

Name: htmlziptest.html
File Contents:

Hello World!

This is a test for the zip functions in PHP.


Definition and Usage

The zip_entry_read() function reads from an open directory entry.

Syntax

zip_entry_read(zip_entry, length)

Parameter Values

Parameter Description
zip_entry Required. Specifies the directory entry returned by zip_read()
length Optional. Specifies the number of (uncompressed) bytes to return. Default is 1024

Technical Details

Return Value: The data read or "" on end of file. FALSE on failure
PHP Version: 4.1.0+

❮ PHP Zip Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.