PHP zip_entry_read - Syntax
zip_entry_read(Resource $ziphandler[, int $length]): mixed
The PHP zip_entry_read() function is used to read a content present in an opened entry (a file) of a Zip archive resource handler using zip_entry_open function. It returns the sub resource handler of a content present in a entry (a file) of a zip archive resource handler only if success otherwise a PHP warning.
zip_entry_read(Resource $ziphandler[, int $length]): mixed
resource $zipHandler |
Specifies the Resource Handler of a zip archive file (*Required) |
---|---|
int $length |
Specifies the Bytes to be read from the entry of the zip archive by default 1024. |
Return mixed $content |
Returns the data read, empty string on end of a file, or false on error. |
Open a text file in a zip archieve using zip_entry_read library method in rb mode, Print the content of a file only if the file was opened successfully otherwise print an error message.
<?php
class ZipExample {
public function processZipArchieve() {
$zipHandler = zip_open("./bbminfo.zip");
while($zipEntry = zip_read($zipHandler)) {
/* Opening a File in a Zip Archive */
$flag = zip_entry_open($zipHandler, $zipEntry, "rb");
if ($flag == true) {
// Read the name of a file
$resourceName = zip_entry_name($zipEntry);
// Read the content of a file
$contents = zip_entry_read($zipEntry);
// Print the file name and its content
echo("File: " . $resourceName . "\n");
echo($contents . "\n");
// close the file entry
zip_entry_close($zipEntry);
} else {
echo("Failed to Open. \n");
}
}
zip_close($zipHandler);
}
}
$obj = new ZipExample();
$obj->processZipArchieve();
Open a text file in a zip archieve using zip_entry_read library method in rb mode, Print the first 15 characters (i.e. 15 bytes) of a file only if the file was opened successfully otherwise print an error message.
<?php
class ZipExample {
public function processZipArchieve() {
$zipHandler = zip_open("./bbminfo.zip");
while($zipEntry = zip_read($zipHandler)) {
/* Opening a File in a Zip Archive */
$flag = zip_entry_open($zipHandler, $zipEntry, "rb");
if ($flag == true) {
// Read the content of a file
$contents = zip_entry_read($zipEntry);
// Print the content of a file
echo($contents);
// close the file entry
zip_entry_close($zipEntry);
} else {
echo("Failed to Open. \n");
}
}
zip_close($zipHandler);
}
}
$obj = new ZipExample();
$obj->processZipArchieve();