- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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