← All posts

Zip Files in S3 with PHP and the S3zipper API

Updated 2026-10-21

PHP remains common for back offices, invoicing systems and internal tools — the kind of software that generates a batch of files and needs to hand users a single archive. The S3zipper API fits the same pattern as any other HTTP call.

1. Get a token

2. Start the zip

$payload = [
    "awsKey"    => getenv("AWS_ACCESS_KEY_ID"),
    "awsSecret" => getenv("AWS_SECRET_ACCESS_KEY"),
    "awsBucket" => "my-bucket",
    "awsRegion" => "us-east-1",
    "filePaths" => ["my-bucket/invoices/2026-10"],
    "zipFileName" => "invoices-2026-10.zip",
];

$start = json_decode(
    request("POST", "https://api.s3zipper.com/v1/zipstart", $auth, json_encode($payload)),
    true
);
echo "Queued: " . $start["taskUUID"][0]["streams3v2"];

3. Wait and fetch the link

for ($i = 0; $i < 120; $i++) {
    $state = json_decode(
        request("POST", "https://api.s3zipper.com/v1/zipstate", $auth, json_encode($start)),
        true
    );
    if (in_array($state["State"], ["SUCCESS", "FAILURE"], true)) break;
    sleep(2);
}

$result = json_decode(
    request("POST", "https://api.s3zipper.com/v1/zipresult", $auth, json_encode($start)),
    true
);
$url = $result["results"][0];

Redirect or link the user to $url. It is a signed S3 link that expires; requesting it again returns the same URL.

Notes

  • Reuse $token within one request cycle; it is valid for a day.
  • For large archives, do not block a PHP request on the loop — queue the job id and check it later, or use resultsEmail.
  • Store credentials outside the repository; hard-coded keys are the most common cause of leaked S3 data.

Try it on your own bucket

Create a free account and zip S3 files on the fly — no downloads, no local disk.

Create free account API docs

← All posts