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中文網其他相關文章!