/** * Uncompresses a gzipped file * * @param string $gzipped * @param string $destination * @return boolean result */ public static function uncompressFile($gzipped, $destination) { if (!@is_file($gzipped)) { return false; } $sourceFile = new ZipFile($gzipped, 'rb'); $filesize = $sourceFile->getFileSize(); $targetFile = new File($destination); while (!$sourceFile->eof()) { $targetFile->write($sourceFile->read(512), 512); } $targetFile->close(); $sourceFile->close(); @$targetFile->chmod(0777); if ($filesize != filesize($destination)) { @unlink($destination); return false; } return true; }
/** * @see Form::save() */ public function save() { parent::save(); // test compression $file = new File($this->fileName, 'rb'); if ($file->read(2) == "‹") { $this->isGzip = true; $zipFile = new ZipFile($this->fileName, 'rb'); $this->fileSize = $zipFile->getFileSize(); } else { $this->fileSize = filesize($this->fileName); } $file->close(); $this->dbName = WCF::getDB()->getDatabaseName(); // build session data array $sessionData = array(); $sessionData['isGzip'] = $this->isGzip; $sessionData['extendedCommand'] = ''; $sessionData['importFile'] = $this->fileName; $sessionData['isTmpFile'] = $this->isTmpFile; $sessionData['ignoreErrors'] = $this->ignoreErrors; $sessionData['offset'] = 0; $sessionData['errors'] = array('messages' => array(), 'errorDescriptions' => array()); $sessionData['tableErrors'] = array(); $sessionData['commandCount'] = 0; $sessionData['wcfCharset'] = WCF::getDB()->getCharset(); $sessionData['importCharset'] = ''; $sessionData['filesize'] = $this->fileSize; $sessionData['remain'] = $sessionData['count'] = $this->fileSize; WCF::getSession()->register('databaseImportData', $sessionData); $this->saved(); WCF::getTPL()->assign(array('pageTitle' => WCF::getLanguage()->get('wcf.acp.db.import.pageHeadline'), 'url' => 'index.php?action=DatabaseImport&packageID=' . PACKAGE_ID . SID_ARG_2ND_NOT_ENCODED, 'progress' => 0)); WCF::getTPL()->display('worker'); exit; }