PHP zip_entry_filesize - Syntax
zip_entry_filesize(resource $ziphandler): int
The PHP zip_entry_filesize() function is used to retrieve the original size of a file (i.e. un-compressed file size) 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_filesize(resource $ziphandler): int
resource $zipHandler |
Specifies the Resource Handler of a zip archive file (*Required) |
---|---|
Return int $fileSize |
Returns the original size of a file in bytes only if success otherwise it will throw a PHP warning. |
Open a zip archieve and print the original 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 original file size in bytes (i.e. un-compressed file size)
$fileSize = zip_entry_filesize($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 actual file size (i.e. un-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 original file size in bytes
$fileSize = zip_entry_filesize($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();