ZipArchive中的多行注释

时间:2017-03-30 08:16:02

标签: php zip php-7 ziparchive winrar

我正在尝试使用ZipArchive设置多行注释.Below是一个简化的演示。

<?php
$comment = "File \t Stats\r\n";
$comment .= "Second line ...some another text \r\n";
$zip->setArchiveComment($comment);

然后我在我的Windows机器上用Winrar打开zip文件,在评论中你可以看到\r\n\t按原样显示...表示winrar不允许这样或者我错误设置了zipArchive评论。

1 个答案:

答案 0 :(得分:0)

我无法根据您的简化演示重现您的问题。 WinRAR按预期显示它。但我可以通过使用single quotes作为注释字符串来模仿您获得的结果。

<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip', ZipArchive::CREATE);
if ($res === TRUE) {
    $zip->addFromString('test.txt', 'file content goes here');

    $zip->setArchiveComment("File \t Stats\r\nSecond line ... some other text \r\n"); // OK
    $comment = "File \t Stats\r\n";
    $comment .= 'Second line ... some other text \r\n';
    $zip->setArchiveComment($comment); // NOT OK for the second line

    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}