- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/main.php
- Класс: CAllMain
- Вызов: CAllMain::SaveFileContent
public function SaveFileContent($abs_path, $strContent)
{
$strContent = str_replace("rn", "n", $strContent);
$file = array();
$this->ResetException();
foreach(GetModuleEvents("main", "OnBeforeChangeFile", true) as $arEvent)
{
if(ExecuteModuleEventEx($arEvent, array($abs_path, &$strContent)) == false)
{
if(!$this->GetException())
$this->ThrowException(GetMessage("main_save_file_handler_error", array("#HANDLER#"=>$arEvent["TO_NAME"])));
return false;
}
}
$io = CBXVirtualIo::GetInstance();
$fileIo = $io->GetFile($abs_path);
$io->CreateDirectory($fileIo->GetPath());
if($fileIo->IsExists())
{
$file["exists"] = true;
if (!$fileIo->IsWritable())
$fileIo->MarkWritable();
$file["size"] = $fileIo->GetFileSize();
}
/****************************** QUOTA ******************************/
if (COption::GetOptionInt("main", "disk_space") > 0)
{
$quota = new CDiskQuota();
if (false === $quota->checkDiskQuota(array("FILE_SIZE" => intval(mb_strlen($strContent) - intVal($file["size"])))))
{
$this->ThrowException($quota->LAST_ERROR, "BAD_QUOTA");
return false;
}
}
/****************************** QUOTA ******************************/
if ($fileIo->PutContents($strContent))
{
$fileIo->MarkWritable();
}
else
{
if ($file["exists"])
$this->ThrowException(GetMessage("MAIN_FILE_NOT_CREATE"), "FILE_NOT_CREATE");
else
$this->ThrowException(GetMessage("MAIN_FILE_NOT_OPENED"), "FILE_NOT_OPEN");
return false;
}
bx_accelerator_reset();
$site = CSite::GetSiteByFullPath($abs_path);
$DOC_ROOT = CSite::GetSiteDocRoot($site);
if(mb_strtoupper(mb_substr(PHP_OS, 0, 3)) === 'WIN')
{
//Fix for name case under Windows
$abs_path = mb_strtolower($abs_path);
$DOC_ROOT = mb_strtolower($DOC_ROOT);
}
if(mb_strpos($abs_path, $DOC_ROOT) === 0 && $site!==false)
{
$DOC_ROOT = rtrim($DOC_ROOT, "/\");
$path = "/".ltrim(mb_substr($abs_path, mb_strlen($DOC_ROOT)), "/\");
foreach(GetModuleEvents("main", "OnChangeFile", true) as $arEvent)
ExecuteModuleEventEx($arEvent, array($path, $site));
}
/****************************** QUOTA ******************************/
if (COption::GetOptionInt("main", "disk_space") > 0)
{
$fs = $fileIo->GetFileSize();
CDiskQuota::updateDiskQuota("files", intval($fs - intVal($file["size"])), "update");
}
/****************************** QUOTA ******************************/
return true;
}