PHP ZipArchive deleteIndex() Function
The ZipArchive::deleteIndex() function is an inbuilt function in PHP that is used to delete an entry from the zip archive using its index.
Syntax:
bool ZipArchive::deleteIndex(int $index)
Parameters: This function accepts a single parameter that is described below:
- $index: This parameter holds the index number of entries that need to delete.
Return Value: This function returns True on Success and False on Failure.
Example 1: The following code demonstrates the delete() function. It deletes the third file as shown in the output.
PHP
<?php
$zip = new ZipArchive;
if ( $zip ->open( 'Geeks.zip' , ZipArchive::CREATE)) {
if ( $zip ->deleteIndex(2)) {
echo 'File deleted successfully' ;
} else {
echo 'File not deleted' ;
}
$zip ->close();
}
else
{
echo 'Failed to open zip file' ;
}
?>
|
Output:
Example 2: The following code demonstrates the delete() function with index 2.
PHP
<?php
$zip = new ZipArchive;
if ( $zip ->open( 'Geeks.zip' , ZipArchive::CREATE)) {
$zip ->addFromString(
'GFG1.txt' ,
'Welcome to GeeksforGeeks'
);
$zip ->addFromString(
'GFG2.txt' ,
'A computer science portal'
);
$zip ->addFromString(
'GFG3.txt' ,
'Welcome to GeeksforGeeks'
);
if ( $zip ->deleteIndex(2))
{
echo 'File deleted successfully' ;
}
else
{
echo 'File not deleted' ;
}
$zip ->close();
}
else
{
echo 'Failed to open zip file' ;
}
?>
|
Output:
Reference: https://www.php.net/manual/en/ziparchive.deleteindex.php
Last Updated :
27 Mar, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...