Skip to content

Instantly share code, notes, and snippets.

@tomasvitek
Created April 3, 2013 04:06
Show Gist options
  • Save tomasvitek/5298372 to your computer and use it in GitHub Desktop.
Save tomasvitek/5298372 to your computer and use it in GitHub Desktop.
Simple utility to unzip an archive remotely on a webserver. When you have to deploy a lot of files to a webserver with no SSH access, upload all files in a zip, upload this script and unzip by calling `http://example.com/extract.php?name_of_archive`.
<?php
/**
* Extracts a zip archive
*
* Simple utility to unzip an archive remotely on a webserver. When you have to deploy
* a lot of files to a webserver with no SSH access, upload all files in a zip, upload
* this script and unzip by calling `http://example.com/extract.php?name_of_archive`.
*
* @copyright Copyright (c) 2013 Tomas Vitek
* @author Tomas Vitek ~ http://tomasvitek.com
* @version 0.1
*/
$zip = new ZipArchive;
$file = urldecode($_SERVER['QUERY_STRING']);
$result = $zip->open($file . '.zip');
if ($result === TRUE) {
if (@$zip->extractTo(__DIR__))
echo '<h1>Done! 👍</h1>';
else
echo '<h1>Failed! 👎</h1><p>Check if PHP can write to the folder.</p>';
$zip->close();
} else {
echo '<h1>Failed! 👎</h1><p><strong>Fail code:</strong> ' . $result . '</p>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment