PHP Zip context options

WBOY
Release: 2023-08-19 22:54:01
forward
1097 people have browsed it

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();
>>
Copy after login

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);
?>
Copy after login

The above is the detailed content of PHP Zip context options. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!