• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/file_dialog.php
  • Класс: CAdminFileDialog
  • Вызов: CAdminFileDialog::UploadFile
static function UploadFile($Params)
{
	$buffer = 'parent.oWaitWindow.Hide();';
	$F = $Params['file'];

	$io = CBXVirtualIo::GetInstance();

	if (isset($F["tmp_name"]) && $F["tmp_name"] <> '' && $F["name"] <> '' || is_uploaded_file($F["tmp_name"]))
	{
		global $APPLICATION, $USER;
		$strWarning = '';
		$filename = $Params['filename'];
		$path = $Params['path'];
		$site = $Params['site'];
		$upload_and_open = $Params['upload_and_open'];
		$rootPath = CSite::GetSiteDocRoot($site);

		if($filename == '')
			$filename = $F["name"];

		$pathto = Rel2Abs($path, $filename);

		if ($filename <> '' && ($mess = self::CheckFileName($filename)) !== true)
			$strWarning = $mess;

		if($strWarning == '')
		{
			$fn = $io->ExtractNameFromPath($pathto);
			if($USER->CanDoFileOperation('fm_upload_file', array($site, $pathto)) &&
				($USER->IsAdmin() || (!HasScriptExtension($fn) && mb_substr($fn, 0, 1) != "." && $io->ValidateFilenameString($fn)))
			)
			{
				if(!$io->FileExists($rootPath.$pathto) || $_REQUEST["rewrite"] == "Y")
				{
					//************************** Quota **************************//
					$bQuota = true;
					$quota = null;
					if(COption::GetOptionInt("main", "disk_space") > 0)
					{
						$bQuota = false;
						$quota = new CDiskQuota();
						if ($quota->checkDiskQuota(array("FILE_SIZE"=>filesize($F["tmp_name"]))))
							$bQuota = true;
					}
					//************************** Quota **************************//
					if ($bQuota)
					{
						$io->Copy($F["tmp_name"], $rootPath.$pathto);
						$flTmp = $io->GetFile($rootPath.$pathto);
						$flTmp->MarkWritable();

						if(COption::GetOptionInt("main", "disk_space") > 0)
							CDiskQuota::updateDiskQuota("file", $flTmp->GetFileSize(), "copy");

						$buffer = 'setTimeout(function(){parent.oBXDialogControls.Uploader.OnAfterUpload("'.$filename.'", '.($upload_and_open == "Y" ? 'true' : 'false').');}, 50);';
					}
					else
					{
						$strWarning = $quota->LAST_ERROR;
					}
				}
				else
				{
					$strWarning = GetMessage("FD_LOAD_EXIST_ALERT");
				}
			}
			else
			{
				$strWarning = GetMessage("FD_LOAD_DENY_ALERT");
			}
		}
	}
	else
	{
		$strWarning = GetMessage("FD_LOAD_ERROR_ALERT");
	}

	if ($strWarning <> '')
		$buffer = 'alert("'.addslashes(htmlspecialcharsex($strWarning)).'");';

	return '';
}