$bUseCompression = True; if (!extension_loaded('zlib') || !function_exists("gzcompress")) { $bUseCompression = False; } require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/tar_gz.php"; CheckDirPath($_SERVER['DOCUMENT_ROOT'] . BX_PERSONAL_ROOT . "/tmp/templates/"); $tmpfname = $_SERVER['DOCUMENT_ROOT'] . BX_PERSONAL_ROOT . "/tmp/templates/" . md5(uniqid(rand(), true) . ".tar.gz"); $HTTP_ACCEPT_ENCODING = ""; $strError = ""; $path = getLocalPath("templates/" . $ID, BX_PERSONAL_ROOT); if (is_dir($_SERVER["DOCUMENT_ROOT"] . $path)) { $oArchiver = new CArchiver($tmpfname, $bUseCompression); $tres = $oArchiver->add("\"" . $_SERVER["DOCUMENT_ROOT"] . $path . "\"", false, $_SERVER["DOCUMENT_ROOT"] . $path); if (!$tres) { $strError = "Archiver error"; $arErrors =& $oArchiver->GetErrors(); if (count($arErrors) > 0) { $strError .= ":<br>"; foreach ($arErrors as $value) { $strError .= "[" . $value[0] . "] " . $value[1] . "<br>"; } } else { $strError .= ".<br>"; } } header('Pragma: public'); header('Cache-control: private'); header("Content-Type: application/force-download; name=\"" . $ID . ".tar.gz\""); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize($tmpfname)); header("Content-Disposition: attachment; filename=\"" . $ID . ".tar.gz\"");
function UnpackFileArchive($strfile, $path_to) { global $APPLICATION; $res = true; $arcname = CTempFile::GetFileName(md5(uniqid(rand(), true)) . '.tar.gz'); CheckDirPath($arcname); if (file_put_contents($arcname, $strfile) !== false) { include_once dirname(__FILE__) . '/tar_gz.php'; $ob = new CArchiver($arcname); CheckDirPath($_SERVER['DOCUMENT_ROOT'] . $path_to); $res = $ob->extractFiles($_SERVER['DOCUMENT_ROOT'] . $path_to); if (!$res && is_object($APPLICATION)) { $arErrors = $ob->GetErrors(); if (count($arErrors)) { $strError = ""; foreach ($arErrors as $error) { $strError .= $error[1] . "<br>"; } $e = new CApplicationException($strError); $APPLICATION->ThrowException($e); } } } return $res; }
/** * Imports an xml file into iblock. File may be an .tar.gz archive. * * @param string $file_name Name of the file to import * @param string $iblock_type IBlock type ID to import iblock to * @param string|array $site_id ID of the site or array of IDs to bind iblock to * @param string $section_action What to do with sections missed in the file. D - delete or A - deactivate. * @param string $element_action What to do with elements missed in the file. D - delete or A - deactivate. * @param bool $use_crc Whenever to use CRC check for optimizi=ation or force an update * @param bool $preview If true when use iblock settings to generate preview pictures from detail. * @param bool $sync If true uses alternative set of tables in order not to interfere with other import processes * @param bool $return_last_error If true will return string with error description in case of failure * @param bool $return_iblock_id If true will return iblock identifier (int) in case of success * @return bool|int|string */ function ImportXMLFile($file_name, $iblock_type = "-", $site_id = '', $section_action = "D", $element_action = "D", $use_crc = false, $preview = false, $sync = false, $return_last_error = false, $return_iblock_id = false) { /** @global CMain $APPLICATION */ global $APPLICATION; $ABS_FILE_NAME = false; if (strlen($file_name) > 0) { if (file_exists($file_name) && is_file($file_name) && (substr($file_name, -4) === ".xml" || substr($file_name, -7) === ".tar.gz")) { $ABS_FILE_NAME = $file_name; } else { $filename = trim(str_replace("\\", "/", trim($file_name)), "/"); $FILE_NAME = rel2abs($_SERVER["DOCUMENT_ROOT"], "/" . $filename); if (strlen($FILE_NAME) > 1 && $FILE_NAME === "/" . $filename && $APPLICATION->GetFileAccessPermission($FILE_NAME) >= "W") { $ABS_FILE_NAME = $_SERVER["DOCUMENT_ROOT"] . $FILE_NAME; } } } if (!$ABS_FILE_NAME) { return GetMessage("IBLOCK_XML2_FILE_ERROR"); } $WORK_DIR_NAME = substr($ABS_FILE_NAME, 0, strrpos($ABS_FILE_NAME, "/") + 1); if (substr($ABS_FILE_NAME, -7) == ".tar.gz") { include_once $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/classes/general/tar_gz.php"; $obArchiver = new CArchiver($ABS_FILE_NAME); if (!$obArchiver->ExtractFiles($WORK_DIR_NAME)) { $strError = ""; if (is_object($APPLICATION)) { $arErrors = $obArchiver->GetErrors(); if (count($arErrors)) { foreach ($arErrors as $error) { $strError .= $error[1] . "<br>"; } } } if ($strError != "") { return $strError; } else { return GetMessage("IBLOCK_XML2_FILE_ERROR"); } } $IMP_FILE_NAME = substr($ABS_FILE_NAME, 0, -7) . ".xml"; } else { $IMP_FILE_NAME = $ABS_FILE_NAME; } $fp = fopen($IMP_FILE_NAME, "rb"); if (!$fp) { return GetMessage("IBLOCK_XML2_FILE_ERROR"); } if ($sync) { $table_name = "b_xml_tree_sync"; } else { $table_name = "b_xml_tree"; } $NS = array("STEP" => 0); $obCatalog = new CIBlockCMLImport(); $obCatalog->Init($NS, $WORK_DIR_NAME, $use_crc, $preview, false, false, false, $table_name); if ($sync) { if (!$obCatalog->StartSession(bitrix_sessid())) { return GetMessage("IBLOCK_XML2_TABLE_CREATE_ERROR"); } $obCatalog->ReadXMLToDatabase($fp, $NS, 0, 1024); $xml_root = $obCatalog->GetSessionRoot(); $bUpdateIBlock = false; } else { $obCatalog->DropTemporaryTables(); if (!$obCatalog->CreateTemporaryTables()) { return GetMessage("IBLOCK_XML2_TABLE_CREATE_ERROR"); } $obCatalog->ReadXMLToDatabase($fp, $NS, 0, 1024); if (!$obCatalog->IndexTemporaryTables()) { return GetMessage("IBLOCK_XML2_INDEX_ERROR"); } $xml_root = 1; $bUpdateIBlock = true; } fclose($fp); $result = $obCatalog->ImportMetaData($xml_root, $iblock_type, $site_id, $bUpdateIBlock); if ($result !== true) { return GetMessage("IBLOCK_XML2_METADATA_ERROR") . implode("\n", $result); } $obCatalog->ImportSections(); $obCatalog->DeactivateSections($section_action); $obCatalog->SectionsResort(); $obCatalog = new CIBlockCMLImport(); $obCatalog->Init($NS, $WORK_DIR_NAME, $use_crc, $preview, false, false, false, $table_name); if ($sync) { if (!$obCatalog->StartSession(bitrix_sessid())) { return GetMessage("IBLOCK_XML2_TABLE_CREATE_ERROR"); } } $SECTION_MAP = false; $PRICES_MAP = false; $obCatalog->ReadCatalogData($SECTION_MAP, $PRICES_MAP); $obCatalog->ImportElements(time(), 0); $obCatalog->ImportProductSets(); $obCatalog->DeactivateElement($element_action, time(), 0); if ($sync) { $obCatalog->EndSession(); } if ($return_last_error) { if (strlen($obCatalog->LAST_ERROR)) { return $obCatalog->LAST_ERROR; } } if ($return_iblock_id) { return intval($NS["IBLOCK_ID"]); } else { return true; } }
public function extractGem($sGemName) { require_once $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/classes/general/tar_gz.php"; $sArchiveName = $this->getGemArchieveNameForDownload($sGemName); if (!is_readable($sArchiveName)) { throw new Exception('Gem archieve for ' . $sGemName . ' not found in ' . $sArchiveName); } $sToFolder = dirname(__FILE__) . '/../../gems/'; $oArchiver = new CArchiver($sArchiveName); $bResult = $oArchiver->extractFiles($sToFolder); $arErrors =& $oArchiver->GetErrors(); $aErrors = array(); if (count($arErrors) > 0) { foreach ($arErrors as $value) { $aErrors[] = "[" . $value[0] . "] " . $value[1]; } } if (!empty($aErrors)) { throw new Exception('Errors during extracting Gem "' . $sGemName . '"! ' . implode(PHP_EOL, $aErrors)); } $this->convertGemCharset(dirname(__FILE__) . '/../../gems/' . $sGemName . '/', $bToSite = true); return $sToFolder . $sGemName . '/'; }
<input type="hidden" name="pos" id="pos_id" value="<?php echo $pos; ?> "> <input type="hidden" name="arc_name" id="arc_name_id" value="<?php echo $arc_name; ?> "> <script> reloadPage(2); </script> <? } else { if(count($oArc->GetErrors()) > 0) { $earr = array(); $earr = $oArc->GetErrors(); $e_str = ""; foreach($earr as $val) { $e_str .= $val[1]."<br>"; } echo showMsg(getMsg("ERR_EXTRACT", $lang), $e_str); } else { $strDName = "";
$res = $arc->Add("\"" . $_SERVER["DOCUMENT_ROOT"] . $dir . "\"", false, $_SERVER["DOCUMENT_ROOT"] . $dir); if (!$res) { $arErrors =& $arc->GetErrors(); foreach ($arErrors as $value) { $strError .= "[" . $value[0] . "] " . $value[1] . "<br>"; } } } else { $package = new CCoursePackage($COURSE_ID); if (strlen($package->LAST_ERROR) <= 0) { $success = $package->CreatePackage($tmp_dir); if ($success) { $arc = new CArchiver($_SERVER["DOCUMENT_ROOT"] . $DATA_FILE_NAME, $bUseCompression); $res = $arc->Add("\"" . $_SERVER['DOCUMENT_ROOT'] . $tmp_dir . "\"", false, $_SERVER['DOCUMENT_ROOT'] . $tmp_dir); if (!$res) { $arErrors =& $arc->GetErrors(); foreach ($arErrors as $value) { $strError .= "[" . $value[0] . "] " . $value[1] . "<br>"; } } DeleteDirFilesEx($tmp_dir); } else { $strError .= $package->LAST_ERROR; } } else { $strError .= $package->LAST_ERROR; } } } if (strlen($strError) > 0) { $STEP = 2;