예제 #1
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;
}
예제 #2
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;
 }
예제 #3
0
 //Determine filename.
 //Check if we're dealing with a file with tar.gz or zip in filename.
 if (!strpos($filename, '.tar.gz') && !strpos($filename, '.zip')) {
     show_error($lang['general']['not_valid_file'], 1);
 } else {
     //Check if file isn't too big.
     if ($_FILES['sendfile']['size'] > $maxfilesize) {
         show_error($lang['theme_install']['too_big'], 1, true);
     } else {
         //Save theme-file.
         copy($_FILES['sendfile']['tmp_name'], $dir . '/' . $filename) or die($lang['general']['upload_failed']);
         if (strpos($filename, '.tar.gz')) {
             //Then load the library for extracting the tar.gz-file.
             require_once 'data/inc/lib/tarlib.class.php';
             //Load the tarfile.
             $tar = new TarLib($dir . '/' . $filename);
             //And extract it.
             $tar->Extract(FULL_ARCHIVE, $dir);
             //After extraction: delete the tar.gz-file.
             unlink($dir . '/' . $filename);
         } else {
             //if not tar.gz then this file must be zip
             //Then load the library for extracting the zip-file.
             require_once 'data/inc/lib/unzip.class.php';
             //Load the zipfile.
             $zip = new UnZIP($dir . '/' . $filename);
             //And extract it.
             $zip->extract();
             //After extraction: delete the zip-file.
             unlink($dir . '/' . $filename);
             //If there is a subdirectory like: theme/theme