ZipArchive 中的多行注释
Multi line comment in ZipArchive
我正在尝试设置多行注释 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 注释。
我无法根据您的简化演示重现您的问题。 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';
}
我正在尝试设置多行注释 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 注释。
我无法根据您的简化演示重现您的问题。 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';
}