Skip to content

Commit

Permalink
Support extraction of tar.gz files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndeet committed Jan 5, 2018
1 parent 2d7f49c commit e2fa920
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)
[See contributors on Github](https://github.com/ndeet/unzipper/graphs/contributors)
12 changes: 11 additions & 1 deletion unzipper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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.');
Expand Down

2 comments on commit e2fa920

@LucasCaravallo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

como descargo el archivo?

@ahmdaha210
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.