Skip to content

Instantly share code, notes, and snippets.

@richardhj
Last active June 9, 2016 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save richardhj/5476896 to your computer and use it in GitHub Desktop.
Save richardhj/5476896 to your computer and use it in GitHub Desktop.
Extract the contao zip archive with this script.
<?php
/**
* PHP version 5
*
* Extracts the Contao archive (downloaded from contao.org) and redirects to the install tool.
*
* Usage:
* * Upload this file and the Contao archive in the desired folder
* * Run this script
*
* @author Richard Hen
* @license LGPL
* @copyright Richard Hen 2013
*/
// Prevent server run out
ini_set('memory_limit', '72M');
ini_set('max_execution_time', 160);
// Variables
$absolutePath = realpath('./');
$arrArchives = glob('*.zip');
$strSubdirectory = dirname($_SERVER["SCRIPT_NAME"]);
if (@class_exists('ZipArchive'))
{
/**
* Extract archive
*/
$zip = new ZipArchive();
if ($zip->open($arrArchives[0]) !== TRUE)
{
die ('Could not open archive');
}
$zip->extractTo($absolutePath);
// Define variables before close zip
$strContaoVersion = dirname($zip->getNameIndex(2)); /* contao-x.y.z.zip */
$arrObjects = scandir($absolutePath . '/' . $strContaoVersion);
$zip->close();
/**
* Copy subdirectory's content to ROOT
*/
foreach ($arrObjects as $object)
{
if ($object != '.' && $object != '..')
{
rename($absolutePath . '/' . $strContaoVersion . '/' . $object, $absolutePath . '/' . $object);
}
}
// Delete empty subdirectory
rmdir($absolutePath . '/' . $strContaoVersion);
/**
* Redirect to install tool
*/
if (strlen($strSubdirectory) > 1)
{
header('Location: http://' . $_SERVER["SERVER_NAME"] . $strSubdirectory . '/contao/install.php');
} else
{
header('Location: http://' . $_SERVER["SERVER_NAME"] . '/contao/install.php');
}
// Delete remains
unlink($arrArchives[0]);
unlink(__FILE__);
}
else
{
// ZipArchive does not exist
die ('ZipArchive() is necessary and not available on your web server.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment