Created
April 15, 2014 15:16
-
-
Save pepebe/10740747 to your computer and use it in GitHub Desktop.
Unzip a package on your server from one directory into another one.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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