php[world] 2015 Call for Speakers

ZipArchive::setArchiveComment

(PHP 5 >= 5.2.0, PECL zip >= 1.4.0)

ZipArchive::setArchiveCommentSet the comment of a ZIP archive

Descrierea

bool ZipArchive::setArchiveComment ( string $comment )

Set the comment of a ZIP archive.

Parametri

comment

The contents of the comment.

Valorile întoarse

Întoarce valoarea TRUE în cazul succesului sau FALSE în cazul eșecului.

Exemple

Example #1 Create an archive and set a comment

<?php
$zip 
= new ZipArchive;
$res $zip->open('test.zip'ZipArchive::CREATE);
if (
$res === TRUE) {
    
$zip->addFromString('test.txt''file content goes here');
    
$zip->setArchiveComment('new archive comment');
    
$zip->close();
    echo 
'ok';
} else {
    echo 
'failed';
}
?>
add a note add a note

User Contributed Notes 1 note

up
0
stanislav dot eckert at vizson dot de
18 days ago
Please note that ZIP archives do not support unicode encodings like UTF-8, so multi-byte characters cannot be shown in standard ZIP viewers like WinRAR or 7-zip. However, the text will stored as-is, so it is at least possible to display UTF-8 comments in your own desktop or web applications. If you want to test with PHP and output in a browser, don't forget to set page charset to UTF-8 too:

header("Content-Type: text/plain; charset=utf-8");
To Top