(PHP Extension) Unzip Text File to String
Demonstrates how to open a .zip and extract the 1st file (assuming it's a text file) to a string variable.
<?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();
$success = $zip->OpenZip('qa_data/zips/EC16100.zip');
if ($success != true) {
print $zip->lastErrorText() . "\n";
exit;
}
// Get the 1st file in the .zip
// entry is a CkZipEntry
$entry = $zip->GetEntryByIndex(0);
if ($zip->get_LastMethodSuccess() != true) {
print 'No files in this zip.' . "\n";
exit;
}
$fileContents = $entry->unzipToString(0,'utf-8');
print $fileContents . "\n";
?>
|