note 128937 added to ziparchive.setarchivecomment

From: Date: Mon, 09 Oct 2023 07:01:38 +0000
Subject: note 128937 added to ziparchive.setarchivecomment
Groups: php.notes 
Request: Send a blank email to php-notes+get-220896@lists.php.net to get a copy of this message
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(); } } ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 240e:45a:94:e417:780a:4238:5e6f:9e42) ---- Manual Page -- https://php.net/manual/en/ziparchive.setarchivecomment.php Edit -- https://main.php.net/note/edit/128937 Del: integrated -- https://main.php.net/note/delete/128937/integrated Del: useless -- https://main.php.net/note/delete/128937/useless Del: bad code -- https://main.php.net/note/delete/128937/bad+code Del: spam -- https://main.php.net/note/delete/128937/spam Del: non-english -- https://main.php.net/note/delete/128937/non-english Del: in docs -- https://main.php.net/note/delete/128937/in+docs Del: other reasons-- https://main.php.net/note/delete/128937 Reject -- https://main.php.net/note/reject/128937 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220896) next »