How can I extract a password protected .zip file from within my PHP application?
How can I extract a password protected .zip
file 开发者_如何学Cfrom within my PHP application?
Since PHP 5.6.0 you can use the class ZipArchive. Encrypted files can be decrypted by setting a password with the setPassword() method.
$zip = new ZipArchive();
if ($zip->open('file.zip') === true) {
$zip->setPassword('MyPassword');
$zip->extractTo('/my/destination/dir/');
$zip->close();
}
You can use this (assuming your server has the "right" os :-))
echo shell_exec('unzip -P password file.zip');
精彩评论