PHP zip_entry_compressedsize - Syntax
zip_entry_compressedsize(resource $ziphandler): int
The PHP zip_entry_compressedsize() function is used to retrieve the compressed size of a file or directory from a specified zip archive entry and it returns the value in bytes only if Success otherwise it will throw a PHP Warning.
zip_entry_compressedsize(resource $ziphandler): int
resource $zipHandler |
Specifies the Resource Handler of a zip archive file (*Required) |
---|---|
Return int $fileSize |
Returns the compressed size of a file or directory in bytes only if success otherwise it will throw a PHP warning. |
Open a zip archieve and print the compressed file size of all entries.
<?php
class ZipExample {
public function processZipArchieve() {
$zipHandler = zip_open("./bbminfo.zip");
if(is_resource($zipHandler)) {
while($zipEntry = zip_read($zipHandler)) {
// Get the file name
$fileName = zip_entry_name($zipEntry);
// Get the compressed file size in bytes
$fileSize = zip_entry_compressedsize($zipEntry);
echo("File: " . $fileName . " (" . $fileSize . " bytes)");
echo "\n" ;
}
zip_close($zipHandler);
} else {
echo("Failed to Open. Error Code: " . $zipHandler);
}
}
}
$obj = new ZipExample();
$obj->processZipArchieve();
Open a zip archieve which contains the nested folders and print the compressed file size of all entries.
<?php
class ZipExample {
public function processZipArchieve() {
$zipHandler = zip_open("./bbminfo-nested-folder.zip");
if(is_resource($zipHandler)) {
while($zipEntry = zip_read($zipHandler)) {
// Get the file name
$resourceName = zip_entry_name($zipEntry);
// Get the compressed file size in bytes
$fileSize = zip_entry_compressedsize($zipEntry);
if(substr($resourceName, -1) == "/") {
echo("Directory: " . $resourceName);
} else {
echo("File: " . $resourceName . " (" . $fileSize . " bytes)");
}
echo "\n" ;
}
zip_close($zipHandler);
} else {
echo("Failed to Open. Error Code: " . $zipHandler);
}
}
}
$obj = new ZipExample();
$obj->processZipArchieve();