PHP ZipArchive::addEmptyDir() Function
Last Updated :
23 Mar, 2023
The ZipArchive::addEmptyDir() function is an inbuilt function in PHP which is used to add a new directory.
Syntax:
bool ZipArchive::addEmptyDir( string $dirname , int $flags = 0 )
Parameters: This method accepts two parameters as mentioned above and described below:
- $dirname: It specifies the directory name to add.
- $flags: It specifies the Bitmask consisting of ZipArchive::FL_ENC_GUESS, ZipArchive::FL_ENC_UTF_8, ZipArchive::FL_ENC_CP437.
Return Value: This function returns true on success or false on failure.
Example 1:
PHP
<?php
$zip = new ZipArchive;
if ( $zip ->open( 'Geeks.zip' )) {
if ( $zip ->addEmptyDir( 'GeeksforGeeks' )) {
echo 'Added an empty directory' ;
} else {
echo 'Directory can not created' ;
}
$zip ->close();
}
else {
echo 'Failed to open zip file' ;
}
?>
|
Output:
Added an empty directory
Example 2:
PHP
<?php
$zip = new ZipArchive;
if ( $zip ->open( 'ide.zip' )) {
$zip ->addEmptyDir( 'GeeksforGeeks' );
$zip ->close();
}
else {
echo 'Failed to open zip file' ;
}
?>
|
Output: Directory added into the zip file. You can open the zip file to check the added directory list.
Reference: https://www.php.net/manual/en/ziparchive.addemptydir.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...