diff options
author | Paul S. Owen <psotfx@users.sourceforge.net> | 2003-07-21 17:32:42 +0000 |
---|---|---|
committer | Paul S. Owen <psotfx@users.sourceforge.net> | 2003-07-21 17:32:42 +0000 |
commit | 71cc8e79b3cecab6ea401d59e29f0ba933b18bdb (patch) | |
tree | 44083f1b882f78e153576a4354ec8583795e400d /phpBB/includes/functions_compress.php | |
parent | 760bf9dbb2d60b29b80ba4b16f5cc1f8535d2eb9 (diff) | |
download | forums-71cc8e79b3cecab6ea401d59e29f0ba933b18bdb.tar forums-71cc8e79b3cecab6ea401d59e29f0ba933b18bdb.tar.gz forums-71cc8e79b3cecab6ea401d59e29f0ba933b18bdb.tar.bz2 forums-71cc8e79b3cecab6ea401d59e29f0ba933b18bdb.tar.xz forums-71cc8e79b3cecab6ea401d59e29f0ba933b18bdb.zip |
Extraction of .tar, .tar.gz and .tar.bz2
git-svn-id: file:///svn/phpbb/trunk@4308 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/functions_compress.php')
-rw-r--r-- | phpBB/includes/functions_compress.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php index e0ab1fc64e..ac0ba106bb 100644 --- a/phpBB/includes/functions_compress.php +++ b/phpBB/includes/functions_compress.php @@ -241,6 +241,49 @@ class compress_tar extends compress function extract($dst) { $fzread = ($this->isbz && function_exists('bzread')) ? 'bzread' : (($this->isgz && extension_loaded('zlib')) ? 'gzread' : 'fread'); + + $header = $data = ''; + $size = 0; + while ($buffer = $fzread($this->fp, 512)) + { + $tmp = unpack("A6magic", substr($buffer, 257, 6)); + + if (trim($tmp['magic']) == 'ustar') + { + $tmp = unpack("A100name", $buffer); + $filename = trim($tmp['name']); + + $tmp = unpack("Atype", substr($buffer, 156, 1)); + $filetype = (int) trim($tmp['type']); + + if ($filetype == 5) + { + mkdir($dst . $filename); + continue; + } + else + { + $tmp = unpack("A12size", substr($buffer, 124, 12)); + $filesize = octdec((int) trim($tmp['size'])); + + if (!($fp = fopen($dst . $filename, 'wb'))) + { + trigger_error('Could not open file for output'); + } + + $size = 0; + continue; + } + } + + $size += 512; + $length = ($size > $filesize) ? 512 - ($size - $filesize) : 512; + + $tmp = unpack("A512data", $buffer); + + fwrite($fp, (string) $tmp['data'], $length); + unset($buffer); + } } function close() @@ -290,6 +333,7 @@ class compress_tar extends compress $fzwrite($this->fp, pack("a512", $buffer)); $i += 512; } + unset($data); } } |