Open In App

PHP ZipArchive getArchiveComment() Function

Last Updated : 23 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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.

  • $flag: This parameter holds the flag and if the flag is set to  ZipArchive::FL_UNCHANGED, then an unchanged archive comment is returned.

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

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

PHP




<?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




<?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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads