首页  >  文章  >  后端开发  >  PHP Zip上下文选项

PHP Zip上下文选项

WBOY
WBOY转载
2023-08-19 22:49:141113浏览

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();
>>

要从zip://流中读取文件,请使用以下代码

<?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);
?>

以上是PHP Zip上下文选项的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除