PHP's ZIP extension registers zip:// wrapper. PHP 7.2.0 onwards supports passwords for encrypted archives. There is only one Zip context option called password
First create ZIP archive as follows:
<?php $zip = new ZipArchive; $zip->open('test.zip'); $zip->setPassword("MySecretPassword"); $zip->addFile('c:/xampp/php/test.txt', 'test.txt'); $zip->close(); >>
要从zip://流中读取文件,请使用以下代码
<?php $opts = array( 'zip' => array( 'password' => 'secret', ), ); $context = stream_context_create($opts); echo file_get_contents('zip://test.zip#test.txt', false, $context); ?>
以上是PHP Zip上下文选项的详细内容。更多信息请关注PHP中文网其他相关文章!