Reading password protected zip files is possible from PHP 7.2.
ZIP extension registers zip wrapperzip://. As of PHP 7.2.0, support for the passwords for encrypted achives were added, allowing passwords to be supplied by stream contexts. Passwords can be set using the 'password' stream context option.
This also solves the problem of requiring the use of program execution functions, which are usually disabled in shared hosting.
Example - Basic password usage example
<?php
// Read encrypted archive
$opts = array(
'zip' => array(
'password' => 'secret',
),
);
// create the context...
$context = stream_context_create($opts);
// ...and use it to fetch the data
echo file_get_contents('zip://test.zip#test.txt', false, $context);
?>
Example - for extraction of files from password protected ZIP archives:
<?php
$zip = new ZipArchive();
$zip_status = $zip->open("test.zip");
if ($zip_status === true){
if ($zip->setPassword('secret')){
if (!$zip->extractTo(__DIR__))
echo "Extraction failed (wrong password?)";
}
$zip->close();
} else {
die("Failed opening archive: ". $zip->getStatusString() . " (code: ". $zip_status .")");
}
?>
Reading password protected zip files is possible from PHP 7.2.
ZIP extension registers zip wrapper
zip://
. As of PHP 7.2.0, support for the passwords for encrypted achives were added, allowing passwords to be supplied by stream contexts. Passwords can be set using the 'password' stream context option.This also solves the problem of requiring the use of program execution functions, which are usually disabled in shared hosting.
Example - Basic password usage example
Example - for extraction of files from password protected ZIP archives:
Example - Archive and encrypt a file
With reference to what is said here: #60