Skip to content

Instantly share code, notes, and snippets.

@pepebe
Created April 15, 2014 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pepebe/10740747 to your computer and use it in GitHub Desktop.
Save pepebe/10740747 to your computer and use it in GitHub Desktop.
Unzip a package on your server from one directory into another one.
<?php
$filename = "";
if(empty($filename)){
$filename = basename($filename,'.zip');
$tmp_path = 'assets/tmp/';
$target_path = 'assets/tpl/';
$basepath = '/paas/cXXXX/www/'; /* Add your server path here... */
$tmp_path = $basepath.$tmp_path.$filename.".zip";
$target_path = $basepath.$target_path.$filename."/";
function extractZip($tmp_path, $target_path, $filename)
{
if (file_exists($tmp_path)){
$zip = new ZipArchive;
$res = $zip->open($tmp_path);
if ($res === TRUE)
{
$zip->extractTo($target_path);
$zip->close();
return '<p>' . $filename . ' file has been extracted to: ' . $target_path . '</p>';
}
else
{
return '<p>There was a problem opening the zip file: ' . $res . '</p>';
}
}
else{
return "<p>There was an error downloading, writing or accessing the zip file.</p>";
}
}
echo extractZip($tmp_path,$target_path,$filename);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment