Sample code for 30+ languages & platforms
PHP

Download a Zip from a URL and OpenBd. (No .zip file is created)

See more Zip Examples

Demonstrates how to download a .zip from a URL, opens the Zip, and gets the contents of a file. No file is ever written.

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\BinData;
use Chilkat2\Http;
use Chilkat2\StringBuilder;
use Chilkat2\Zip;
use Chilkat2\ZipEntry;

$success = false;

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

$http = new Http();

$bd = new BinData();

// This URL is valid and can be tested...
try {
    $http->QuickGetBd('https://chilkatdownload.com/example_data/hamlet.zip', $bd);

    $zip = new Zip();

    // Open the zip from the bytes contained in bd.
    $zip->OpenBd($bd);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

// Get the entry for the file we want..
$entry = new ZipEntry();
$success = $zip->EntryOf('hamlet.xml', $entry);
if (!$success) {
    echo $zip->LastErrorText, "\n";
    exit;
}

// Convert all line endings to CRLF (if needed)
$lineEndingBehavior = 2;
try {
    $xmlStr = $entry->UnzipToString($lineEndingBehavior, 'utf-8');
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

// The XML in this case is about 274K, so let's just examine the last 20 lines...
$sb = new StringBuilder();
$sb->Append($xmlStr);

echo $sb->LastNLines(20, true), "\n";