Sample code for 30+ languages & platforms
PHP ActiveX

Compress Bytes

See more Compression Examples

Demonstrates how to compress binary data.

Chilkat PHP ActiveX Downloads

PHP ActiveX
<?php

$success = 0;

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

$fac = new COM("Chilkat.FileAccess");

$fileBytes = $fac->ReadEntireFile('qa_data/bmp/big.bmp');
if ($fac->LastMethodSuccess != 1) {
    print $fac->LastErrorText . "\n";
    exit;
}

$compress = new COM("Chilkat.Compression");
$compress->Algorithm = 'deflate';

$compressedBytes = $compress->CompressBytes($fileBytes);
if ($compress->LastMethodSuccess != 1) {
    print $compress->LastErrorText . "\n";
    exit;
}

$success = $fac->WriteEntireFile('qa_output/compressedBmp.dat',$compressedBytes);
if ($fac->LastMethodSuccess != 1) {
    print $fac->LastErrorText . "\n";
    exit;
}


?>