首頁  >  文章  >  後端開發  >  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刪除