Skip to content

Commit e2fa920

Browse files
committed
Support extraction of tar.gz files.
1 parent 2d7f49c commit e2fa920

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The Unzipper
22

3-
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).
3+
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).
44
As of version 0.1.0 it also supports creating archives.
55

66
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
4141

4242

4343
## Credits
44-
[See contributors on Github](https://github.com/ndeet/unzipper/graphs/contributors)
44+
[See contributors on Github](https://github.com/ndeet/unzipper/graphs/contributors)

unzipper.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public static function extractGzipFile($archive, $destination) {
161161

162162
$filename = pathinfo($archive, PATHINFO_FILENAME);
163163
$gzipped = gzopen($archive, "rb");
164-
$file = fopen($filename, "w");
164+
$file = fopen($destination . '/' . $filename, "w");
165165

166166
while ($string = gzread($gzipped, 4096)) {
167167
fwrite($file, $string, strlen($string));
@@ -172,6 +172,16 @@ public static function extractGzipFile($archive, $destination) {
172172
// Check if file was extracted.
173173
if (file_exists($destination . '/' . $filename)) {
174174
$GLOBALS['status'] = array('success' => 'File unzipped successfully.');
175+
176+
// If we had a tar.gz file, let's extract that tar file.
177+
if (pathinfo($destination . '/' . $filename, PATHINFO_EXTENSION) == 'tar') {
178+
$phar = new PharData($destination . '/' . $filename);
179+
if ($phar->extractTo($destination)) {
180+
$GLOBALS['status'] = array('success' => 'Extracted tar.gz archive successfully.');
181+
// Delete .tar.
182+
unlink($destination . '/' . $filename);
183+
}
184+
}
175185
}
176186
else {
177187
$GLOBALS['status'] = array('error' => 'Error unzipping file.');

0 commit comments

Comments
 (0)