Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
PHP Zip context options
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('test.zip');
$zip->setPassword("MySecretPassword");
$zip->addFile('c:/xampp/php/test.txt', 'test.txt');
$zip->close();
>>
To read file from zip:// stream, use 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);
?> Advertisements
