PHP.mk документација

ZipArchive::setArchiveComment

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

ziparchive.setarchivecomment.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека ziparchive.setarchivecomment.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
ZipArchive::setArchiveComment

Референца за `ziparchive.setarchivecomment.php` со подобрена типографија и навигација.

ziparchive.setarchivecomment.php

ZipArchive::setArchiveComment

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

ZipArchive::setArchiveCommentПостави коментар на ZIP архива

= NULL

public ZipArchive::setArchiveComment(string $comment): bool

Постави коментар на ZIP архива.

Параметри

comment

Пишува целосен коментар.

Вратени вредности

Патеката до PHP скриптата што треба да се провери. true на успех или false при неуспех.

Примери

Пример #1 Креирај архива и постави коментар

<?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';
}
?>

Белешки од корисници 3 белешки

randolphothegreat at yahoo dot com
пред 10 години
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");
(PHP 5 >= 5.2.0, PHP 7, PHP 8, PECL zip >= 1.4.0)
пред 9 години
Zip archives are encoded in ISO-8859-1 when stored but comments seem to be added in UTF-8 everytime. So...

<?php
   $zip->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:

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

    echo 'ok';
} else {
    echo 'failed';
}
?>
solrac at ragnarockradio dot com
пред 2 години
ZipArchive (using libzip) encodes comments in UTF-8/ASCII, but some softwares on Windows show comments in ANSI (such as GBK...), so we should :

<?php
    $_charset = 'GBK';
    $file = 'D:/boaphp.zip';
    $comment = '中文ABC123';
    
    $zip = new ZipArchive;
    $res = $zip->open($file, ZipArchive::CREATE);
    if ($res) {
        //add files here

        if($_charset){ //for Winrar, 7z...
            $zip->close();
            
            $str = mb_convert_encoding($comment, $_charset, 'UTF-8');
            $fh = fopen($file, 'r+b');
            fseek($fh, -2, SEEK_END);
            $str = pack('v', strlen($str)) . $str;
            fwrite($fh, $str);
            fclose($fh);
        }else{ //for PHP: $zip->getArchiveComment()
            $zip->setArchiveComment($comment);
            $zip->close();
        }
    }
?>
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.