<?php $_charset = 'GBK'; // 根据须要转换编码 $file = 'D:/boaphp.zip'; $comment = '中文ABC123'; // 注释 $zip = new ZipArchive; $res = $zip->open($file, ZipArchive::CREATE); if ($res) { // 添加压缩文件 if($_charset){ //适用 Winrar, 7z... $zip->close(); // 把稳:先关闭ZipArchive $str = mb_convert_encoding($comment, $_charset, 'UTF-8'); // 将注释转换为本地编码 $fh = fopen($file, 'r+b'); // 二进制办法打开压缩包 fseek($fh, -2, SEEK_END); // 查找压缩包末了2个字节 $str = pack('v', strlen($str)) . $str; // 天生二进制格式的数据 fwrite($fh, $str); // 从找到位置开始写入 fclose($fh); }else{ //适用 $zip->getArchiveComment() $zip->setArchiveComment($comment); $zip->close(); } }?>
参考
1.Zip文件格式 - DeeLMind - 博客园
2.PHP: ZipArchive::setArchiveComment - Manual
