note 119677 added to ziparchive.addfile

From: Date: Mon, 01 Aug 2016 13:22:58 +0000
Subject: note 119677 added to ziparchive.addfile
Groups: php.notes 
Request: Send a blank email to php-notes+get-206143@lists.php.net to get a copy of this message
如果文件名包含汉字,ZIPARCHIVE::addFile() 会导致无法将文件压缩到压缩包中,或者压缩以后文件名乱码。 可以使用ZipArchive::addFromString()来实现。 注意:如果操作系统是Windows,文件系统编码是gbk. 如果php文件的文件编码是utf-8,需要相应转码。 ZipArchive::addFile() fails if the filename contains Chinese characters. ZipArchive::addFromString() should be used instead. <?php $z = new ZipArchive; $file = '吴先成.txt'; if($z->open(ZIPARCHIVE::CREATE)===true){ $z->addFromString($file, file_get_contents($file)); //for windows //$z->addFromString($file, file_get_contents(iconv('utf-8', 'gbk//ignore', $file))); } // ... ---- Server IP: 72.52.91.14 Probable Submitter: 118.117.77.147 ---- Manual Page -- http://php.net/manual/en/ziparchive.addfile.php Edit -- https://master.php.net/note/edit/119677 Del: integrated -- https://master.php.net/note/delete/119677/integrated Del: useless -- https://master.php.net/note/delete/119677/useless Del: bad code -- https://master.php.net/note/delete/119677/bad+code Del: spam -- https://master.php.net/note/delete/119677/spam Del: non-english -- https://master.php.net/note/delete/119677/non-english Del: in docs -- https://master.php.net/note/delete/119677/in+docs Del: other reasons-- https://master.php.net/note/delete/119677 Reject -- https://master.php.net/note/reject/119677 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#206143) next »