Reputation: 272
How can I extract a password protected .zip
file from within my PHP application?
Upvotes: 13
Views: 8925
Reputation: 2921
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();
}
Upvotes: 8
Reputation: 4199
You can use this (assuming your server has the "right" os :-))
echo shell_exec('unzip -P password file.zip');
Upvotes: 7