/** * Downloads and saves a file. * * @param string $url URI to download * @param string $filePath Absolute file path * @return bool */ public function download($url, $filePath) { $dir = IO\Path::getDirectory($filePath); IO\Directory::createDirectory($dir); $file = new IO\File($filePath); $handler = $file->open("w+"); if ($handler !== false) { $this->setOutputStream($handler); $res = $this->query(self::HTTP_GET, $url); fclose($handler); return $res; } return false; }
public function clearLogFile() { $logDir = $this->getLogFileDir(); if (!Main\IO\Directory::isDirectoryExists($logDir)) { Main\IO\Directory::createDirectory($logDir); } $logFile = $this->getLogFilePath(); Main\IO\File::putFileContents($logFile, ''); }
protected static function cleanWorkDirectory() { $dir = $_SERVER['DOCUMENT_ROOT'] . self::LOCAL_PATH . self::LOCAL_SETS_PATH; IO\Directory::deleteDirectory($dir); IO\Directory::createDirectory($dir); }
protected static function createDirectory($path) { if (!\Bitrix\Main\IO\Directory::isDirectoryExists($path)) { \Bitrix\Main\IO\Directory::createDirectory($path); } }
private static function createIBlock($iblockType, $iblock, $pictureType, $picture, $siteId = null) { if (is_null($siteId)) { $siteId = \CSite::GetDefSite(); } $db = \CIBlock::GetList(array(), array("IBLOCK_TYPE_ID" => $iblockType, "CODE" => $iblock["CODE"], "CHECK_PERMISSIONS" => "N", "SITE_ID" => $siteId)); if ($res = $db->Fetch()) { return $res["ID"]; } $fields = array("NAME" => $iblock["NAME"], "DESCRIPTION" => $iblock["DESCRIPTION"], "IBLOCK_TYPE_ID" => $iblockType, "SORT" => $iblock["SORT"], "CODE" => $iblock["CODE"], "WORKFLOW" => "N", "ELEMENTS_NAME" => $iblock["ELEMENTS_NAME"], "ELEMENT_NAME" => $iblock["ELEMENT_NAME"], "ELEMENT_ADD" => $iblock["ELEMENT_ADD"], "ELEMENT_EDIT" => $iblock["ELEMENT_EDIT"], "ELEMENT_DELETE" => $iblock["ELEMENT_DELETE"], "SECTIONS_NAME" => $iblock["SECTIONS_NAME"], "SECTION_NAME" => $iblock["SECTION_NAME"], "SECTION_ADD" => $iblock["SECTION_ADD"], "SECTION_EDIT" => $iblock["SECTION_EDIT"], "SECTION_DELETE" => $iblock["SECTION_DELETE"], "BIZPROC" => "Y", "SITE_ID" => array($siteId), "RIGHTS_MODE" => "E"); if ($iblock["SOCNET_GROUP_ID"]) { $fields["SOCNET_GROUP_ID"] = $iblock["SOCNET_GROUP_ID"]; } static $exts = array("image/jpeg" => "jpg", "image/png" => "png", "image/gif" => "gif"); if (!empty($picture) && isset($exts[$pictureType])) { $fn = \CTempFile::GetFileName(); Main\IO\Directory::createDirectory($fn); $fn .= md5(mt_rand()) . "." . $exts[$pictureType]; $f = fopen($fn, "wb"); fwrite($f, $picture); fclose($f); $fields["PICTURE"] = \CFile::MakeFileArray($fn); } $ob = new \CIBlock(); $res = $ob->Add($fields); if ($res) { self::createIBlockRights($res); $list = new \CList($res); if (isset($iblock["~NAME_FIELD"])) { $list->UpdateField("NAME", $iblock["~NAME_FIELD"]); } $list->Save(); \CLists::setLiveFeed(1, $res); return $res; } return 0; }