Skip to content

Instantly share code, notes, and snippets.

@antoniocosentino
Created July 9, 2026 19:10
Show Gist options
  • Select an option

  • Save antoniocosentino/3bad1f508ad5b2f3dbd1df04d6b62f7c to your computer and use it in GitHub Desktop.

Select an option

Save antoniocosentino/3bad1f508ad5b2f3dbd1df04d6b62f7c to your computer and use it in GitHub Desktop.
Unzip with PHP
<?php
$zipFile = __DIR__ . '/backup.zip';
$extractTo = __DIR__;
echo "<pre>";
if (!file_exists($zipFile)) {
die("Error: backup.zip not found in " . __DIR__);
}
$zip = new ZipArchive();
$result = $zip->open($zipFile);
if ($result !== true) {
die("Error: Could not open backup.zip (code: $result)");
}
echo "Extracting backup.zip...\n";
if ($zip->extractTo($extractTo)) {
echo "Extraction completed successfully.\n";
} else {
echo "Error: Extraction failed.\n";
}
$zip->close();
echo "</pre>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment