diff --git a/README.md b/README.md index 8b98e7e..968cbaa 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # The Unzipper -The Unzipper extracts .zip and .rar archives or .gz files on webservers. It detects .zip/.rar/.gz archives and let you choose which one to extract (if there are multiple archives available). +The Unzipper extracts .zip and .rar archives or .gz/tar.gz files on webservers. It detects .zip/.rar/.tar.gz/.gz archives and let you choose which one to extract (if there are multiple archives available). As of version 0.1.0 it also supports creating archives. It's handy if you do not have shell access. E.g. if you want to upload a lot of files (php framework or image collection) as archive - because it is much faster than uploading each file by itself. @@ -41,4 +41,4 @@ Get latest code at https://github.com/ndeet/unzipper ## Credits -[See contributors on Github](https://github.com/ndeet/unzipper/graphs/contributors) \ No newline at end of file +[See contributors on Github](https://github.com/ndeet/unzipper/graphs/contributors) diff --git a/unzipper.php b/unzipper.php index 159e988..b7b1bbc 100644 --- a/unzipper.php +++ b/unzipper.php @@ -161,7 +161,7 @@ public static function extractGzipFile($archive, $destination) { $filename = pathinfo($archive, PATHINFO_FILENAME); $gzipped = gzopen($archive, "rb"); - $file = fopen($filename, "w"); + $file = fopen($destination . '/' . $filename, "w"); while ($string = gzread($gzipped, 4096)) { fwrite($file, $string, strlen($string)); @@ -172,6 +172,16 @@ public static function extractGzipFile($archive, $destination) { // Check if file was extracted. if (file_exists($destination . '/' . $filename)) { $GLOBALS['status'] = array('success' => 'File unzipped successfully.'); + + // If we had a tar.gz file, let's extract that tar file. + if (pathinfo($destination . '/' . $filename, PATHINFO_EXTENSION) == 'tar') { + $phar = new PharData($destination . '/' . $filename); + if ($phar->extractTo($destination)) { + $GLOBALS['status'] = array('success' => 'Extracted tar.gz archive successfully.'); + // Delete .tar. + unlink($destination . '/' . $filename); + } + } } else { $GLOBALS['status'] = array('error' => 'Error unzipping file.');