예제 #1
0
 /**
  * Decompress a given file to the given target directory
  *
  * Determines the compression type from the file extension
  */
 function decompress($file, $target)
 {
     global $conf;
     // decompression library doesn't like target folders ending in "/"
     if (substr($target, -1) == "/") {
         $target = substr($target, 0, -1);
     }
     $ext = $this->guess_archive($file);
     if (in_array($ext, array('tar', 'bz', 'gz'))) {
         switch ($ext) {
             case 'bz':
                 $compress_type = TarLib::COMPRESS_BZIP;
                 break;
             case 'gz':
                 $compress_type = TarLib::COMPRESS_GZIP;
                 break;
             default:
                 $compress_type = TarLib::COMPRESS_NONE;
         }
         $tar = new TarLib($file, $compress_type);
         if ($tar->_initerror < 0) {
             if ($conf['allowdebug']) {
                 msg('TarLib Error: ' . $tar->TarErrorStr($tar->_initerror), -1);
             }
             return false;
         }
         $ok = $tar->Extract(TarLib::FULL_ARCHIVE, $target, '', 0777);
         if ($ok < 1) {
             if ($conf['allowdebug']) {
                 msg('TarLib Error: ' . $tar->TarErrorStr($ok), -1);
             }
             return false;
         }
         return true;
     } else {
         if ($ext == 'zip') {
             $zip = new ZipLib();
             $ok = $zip->Extract($file, $target);
             // FIXME sort something out for handling zip error messages meaningfully
             return $ok == -1 ? false : true;
         }
     }
     // unsupported file type
     return false;
 }
예제 #2
0
function ap_decompress($file, $target)
{
    global $conf;
    // decompression library doesn't like target folders ending in "/"
    if (substr($target, -1) == "/") {
        $target = substr($target, 0, -1);
    }
    $ext = substr($file, strrpos($file, '.') + 1);
    // .tar, .tar.bz, .tar.gz, .tgz
    if (in_array($ext, array('tar', 'bz', 'bz2', 'gz', 'tgz'))) {
        require_once DOKU_INC . "inc/TarLib.class.php";
        if (strpos($ext, 'bz') !== false) {
            $compress_type = COMPRESS_BZIP;
        } else {
            if (strpos($ext, 'gz') !== false) {
                $compress_type = COMPRESS_GZIP;
            } else {
                $compress_type = COMPRESS_NONE;
            }
        }
        $tar = new TarLib($file, $compress_type);
        if ($tar->_initerror < 0) {
            if ($conf['allowdebug']) {
                msg('TarLib Error: ' . $tar->TarErrorStr($tar->_initerror), -1);
            }
            return false;
        }
        $ok = $tar->Extract(FULL_ARCHIVE, $target, '', 0777);
        if ($ok < 1) {
            if ($conf['allowdebug']) {
                msg('TarLib Error: ' . $tar->TarErrorStr($ok), -1);
            }
            return false;
        }
        return true;
    } else {
        if ($ext == 'zip') {
            require_once DOKU_INC . "inc/ZipLib.class.php";
            $zip = new ZipLib();
            $ok = $zip->Extract($file, $target);
            // FIXME sort something out for handling zip error messages meaningfully
            return $ok == -1 ? false : true;
        } else {
            if ($ext == "rar") {
                // not yet supported -- fix me
                return false;
            }
        }
    }
    // unsupported file type
    return false;
}