PHP Requires Chilkat v11.0.0+
PHP
Create a Zip Entirely in Memory
See more Zip Examples
Demonstrates how to create a .zip from in-memory byte data and strings, and to write the .zip to an in-memory image.Chilkat PHP Downloads
<?php
use Chilkat2\BinData;
use Chilkat2\Crypt2;
use Chilkat2\FileAccess;
use Chilkat2\Zip;
$success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$crypt = new Crypt2();
$zip = new Zip();
try {
$zip->NewZip('test.zip');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
// Add the bytes 0x00 0x01 0x02 0x03 ... 0x0F as a file in the .zip
$bd = new BinData();
$bd->AppendEncoded('000102030405060708090A0B0C0D0E0F', 'hex');
$zip->AddBd('binaryData.dat', $bd);
// Add the string "Hello World!" to the .zip
$zip->AddString('helloWorld.txt', 'Hello World!', 'utf-8');
ERROR: Method not in Chilkat2 PHP: Zip.WriteToMemory
$zipFileInMemory = $zip->ERROR();
// We could save these files to a file, and it is a valid .zip
$fac = new FileAccess();
ERROR: Method not in Chilkat2 PHP: FileAccess.WriteEntireFile
$success = $fac->ERROR();
if (!$success) {
echo $fac->LastErrorText, "\n";
exit;
}
echo "Zip Created!\n";