PHP ZipArchive count() Function
The ZipArchive::count() function is an inbuilt function in PHP that is used to count the number of files in a zip archive.
Syntax:
int ZipArchive::count()
Parameters: This function does not accept any parameters.
Return Value: This function returns the number of files in the zip archive.
Example 1: The following code demonstrates the total count of a zip file.
PHP
<?php
$zip = new ZipArchive;
if ( $zip ->open( 'Geeks.zip' ))
{
if ( $zip ->addEmptyDir( 'GeeksforGeeks' ));
echo 'Total files/directory: ' . $zip -> count ();
$zip ->close();
}
else
{
echo 'Failed to open zip file' ;
}
?>
|
Output:
Example 2: The following code shows the total number of files after adding the extra 3 files as given in the code.
PHP
<?php
$zip = new ZipArchive;
if ( $zip ->open( 'Geeks.zip' , ZipArchive::CREATE)) {
echo 'Total number of files: '
. $zip -> count () . '<br>' ;
$zip ->addFromString(
'GFG1.txt' ,
'Welcome to GeeksforGeeks'
);
$zip ->addFromString(
'GFG2.txt' ,
'A computer science portal'
);
$zip ->addFromString(
'GFG3.txt' ,
'Welcome to GeeksforGeeks'
);
echo 'Total files after adding new files: '
. $zip -> count ();
$zip ->close();
}
else {
echo 'Failed to open zip file' ;
}
?>
|
Output:
Reference: https://www.php.net/manual/en/ziparchive.count.php
Last Updated :
23 Mar, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...