Home >Backend Development >PHP Tutorial >PHP Zip context options

PHP Zip context options

WBOY
WBOYforward
2023-08-19 22:49:141126browse

PHP Zip上下文选项

Introduction

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

Example

First create ZIP archive as follows:

<?php
$zip = new ZipArchive;
$zip->open(&#39;test.zip&#39;);
$zip->setPassword("MySecretPassword");
$zip->addFile(&#39;c:/xampp/php/test.txt&#39;, &#39;test.txt&#39;);
$zip->close();
>>

To read from the zip:// stream To get the file, please use the following code

<?php
$opts = array(
   &#39;zip&#39; => array(
      &#39;password&#39; => &#39;secret&#39;,
   ),
);
$context = stream_context_create($opts);
echo file_get_contents(&#39;zip://test.zip#test.txt&#39;, 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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:PHP Traversable interfaceNext article:PHP Traversable interface