Home >Backend Development >PHP Tutorial >PHP Zip context options
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(); >>
To read from the zip:// stream To get the file, please use the following code
<?php $opts = array( 'zip' => array( 'password' => 'secret', ), ); $context = stream_context_create($opts); echo file_get_contents('zip://test.zip#test.txt', false, $context); ?>
The above is the detailed content of PHP Zip context options. For more information, please follow other related articles on the PHP Chinese website!