(PHP Extension) Verify a Zip's Password
Demonstrates how to verify the password for an encrypted or password-protected zip archive.
<?php
// The version number (9_5_0) should match version of the Chilkat extension used, omitting the micro-version number.
// For example, if using Chilkat v9.5.0.48, then include as shown here:
include("chilkat_9_5_0.php");
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$zip = new CkZip();
// To verify a password for a Zip, the Zip must be opened:
$success = $zip->OpenZip('myProtected.zip');
if ($success != true) {
print $zip->lastErrorText() . "\n";
exit;
}
// Set the password to be verified:
$zip->put_DecryptPassword('secret');
$passwordOk = $zip->VerifyPassword();
if ($passwordOk == true) {
print 'Password is correct.' . "\n";
}
else {
print 'Password is incorrect.' . "\n";
}
$zip->CloseZip();
?>
|