บทนำ
ส่วนขยาย ZIP ของ PHP ลงทะเบียน wrapper zip:// ตั้งแต่ PHP 7.2.0 รองรับรหัสผ่านสำหรับ archive ที่เข้ารหัส มี Zip context option เพียงตัวเดียวคือ password
ตัวอย่าง
สร้าง ZIP archive ก่อนดังนี้:
<?php $zip = new ZipArchive; $zip->open('test.zip'); $zip->setPassword("MySecretPassword"); $zip->addFile('c:/xampp/php/test.txt', 'test.txt'); $zip->close(); >>เพื่ออ่านไฟล์จาก zip:// stream ใช้โค้ดดังนี้
<?php $opts = array( 'zip' => array( 'password' => 'secret', ), ); $context = stream_context_create($opts); echo file_get_contents('zip://test.zip#test.txt', false, $context); ?>