PHP 7.2.7 Released


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

ZipArchive::setArchiveCommentSetzt einen Kommentar zu einem ZIP-Archiv


bool ZipArchive::setArchiveComment ( string $comment )

Setzt einen Kommentar zu einem ZIP-Archiv.



Der Inhalt des Kommentars.


Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.


Beispiel #1 Ein Archiv erstellen und einen Kommentar hinzufügen

= new ZipArchive;
$res $zip->open(''ZipArchive::CREATE);
if (
$res === TRUE) {
$zip->addFromString('test.txt''Der Dateiinhalt kommt hier');
$zip->setArchiveComment('Neuer Archivkommentar');
} else {
add a note add a note

User Contributed Notes 2 notes

stanislav dot eckert at vizson dot de
3 years 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");
solrac at ragnarockradio dot com
1 year ago
Zip archives are encoded in ISO-8859-1 when stored but comments seem to be added in UTF-8 everytime. So...

->setArchiveComment("Peña");    //outputs "Peña" as the comment.

$zip->setArchiveComment("Peña");    //outputs "NULL" as the comment / no comment is displayed.

Using mb_internal_encoding() or mb_http_output() wont change this behavior.
At the end you can fix your corrupted comment using something like str_replace();

Consider this:

= new ZipArchive;
$res = $zip->open('', ZipArchive::CREATE);
if (
$res === TRUE) {
$zip->addFromString('test.txt', 'file content goes here');
$zip->setArchiveComment('Peña'); //outputs "Peña" as the comment.
$file = file_get_contents('');
file_put_contents('', str_replace("Peña", utf8_decode("Peña"), $file)); //outputs "Peña" as the comment. FIXED!

echo 'ok';
} else {
To Top