Open In App

PHP ZipArchive getArchiveComment() Function

The ZipArchive::getArchiveComment() function is an inbuilt function in PHP that is used to return the zip archive comment.

Syntax:



string|false ZipArchive::getArchiveComment(int $flags = 0)

Parameters: This function accepts a single parameter that is described below.

Return Value: This function returns the zip archive comment or “false” on failure.



Example 1: The following code demonstrates the getArchiveComment() function.




<?php
 
    // Create a new ZipArchive object
    $zip = new ZipArchive;
 
    // Check for opening the zip file
    if ($zip->open('Geeks.zip', ZipArchive::CREATE))
    {
         
        // Get the archive comment
        var_dump($zip->getArchiveComment());
         
        // Close the zip file
        $zip->close();
    }
    // If zip file is not open/exist
    else {
        echo 'Failed to open zip file';
    }
?>

Output:

string(0) ""

Example 2: The following code demonstrates the setArchiveComment() function which set the given string as shown in the output.




<?php
 
    // Create a new ZipArchive object
    $zip = new ZipArchive;
 
    // Check for opening the zip file
    if ($zip->open('Geeks.zip', ZipArchive::CREATE)) {
         
        $zip->setArchiveComment('GeeksforGeeks Archive Comment');
         
        var_dump($zip->getArchiveComment());
         
        // Close the zip file
        $zip->close();
    }
    // If zip file is not open/exist
    else
    {
        echo 'Failed to open zip file';
    }
?>

Output:

string(29) "GeeksforGeeks Archive Comment"

Reference: https://www.php.net/manual/en/ziparchive.getarchivecomment.php


Article Tags :