(PHP ActiveX) Unzip Encrypted Text into a String Variable
Demonstrates how to open an encrypted .zip archive and unzip a text file directly into a string variable.
<?php
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.Zip')
$zip = new COM("Chilkat.Zip");
// Set the password required for decrypting.
$zip->DecryptPassword = 'myPassword';
$success = $zip->OpenZip('encrypted.zip');
if ($success != 1) {
print $zip->LastErrorText . "\n";
exit;
}
// Locate the file within the Zip to be unzipped into a string variable:
// entry is a Chilkat.ZipEntry
$entry = $zip->FirstMatchingEntry('*.csv');
if ($zip->LastMethodSuccess == 0) {
print 'No matching entry found.' . "\n";
exit;
}
// lineEndingBehavior:
// 0 = leave unchanged.
// 1 = convert all to bare LF's
// 2 = convert all to CRLF's
$lineEndingBehavior = 0;
$srcCharset = 'utf-8';
$strCsv = $entry->unzipToString($lineEndingBehavior,$srcCharset);
print $strCsv . "\n";
?>
|