- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/wizard.php
- Класс: CWizardStep
- Вызов: CWizardStep::SaveFile
function SaveFile($name, $arRestriction = Array())
{
$wizard = $this->GetWizard();
$deleteFile = $wizard->GetVar($name."_del");
$wizard->UnSetVar($name."_del");
$oldFileID = $wizard->GetVar($name);
$fileNew = $wizard->GetRealName($name."_new");
if (!array_key_exists($fileNew, $_FILES) || ($_FILES[$fileNew]["name"] == '' && $deleteFile === null))
return;
if ($_FILES[$fileNew]["tmp_name"] == '' && $deleteFile === null)
{
$this->SetError(GetMessage("MAIN_WIZARD_FILE_UPLOAD_ERROR"), $name."_new");
return;
}
$arFile = $_FILES[$fileNew] + Array(
"del" => ($deleteFile == "Y" ? "Y" : ""),
"old_file" => (intval($oldFileID) > 0 ? intval($oldFileID): 0 ),
"MODULE_ID" => "tmp_wizard"
);
$max_file_size = (array_key_exists("max_file_size", $arRestriction) ? intval($arRestriction["max_file_size"]) : 0);
$max_width = (array_key_exists("max_width", $arRestriction) ? intval($arRestriction["max_width"]) : 0);
$max_height = (array_key_exists("max_height", $arRestriction) ? intval($arRestriction["max_height"]) : 0);
$extensions = (array_key_exists("extensions", $arRestriction) && $arRestriction["extensions"] <> '' ? trim($arRestriction["extensions"]) : false);
$make_preview = (array_key_exists("make_preview", $arRestriction) && $arRestriction["make_preview"] == "Y" ? true : false);
$error = CFile::CheckFile($arFile, $max_file_size, false, $extensions);
if ($error <> '')
{
$this->SetError($error, $name."_new");
return;
}
if ($make_preview && $max_width > 0 && $max_height > 0)
{
$info = (new BitrixMainFileImage($arFile["tmp_name"]))->getInfo();
if($info)
{
if ($info->getWidth() > $max_width || $info->getHeight() > $max_height)
{
$success = CWizardUtil::CreateThumbnail($arFile["tmp_name"], $arFile["tmp_name"], $max_width, $max_height);
if ($success)
$arFile["size"] = @filesize($arFile["tmp_name"]);
}
}
}
elseif ($max_width > 0 || $max_height > 0)
{
$error = CFile::CheckImageFile($arFile, $max_file_size, $max_width, $max_height);
if ($error <> '')
{
$this->SetError($error, $name."_new");
return;
}
}
$fileID = (int)CFile::SaveFile($arFile, "tmp");
if ($fileID > 0)
$wizard->SetVar($name, $fileID);
else
$wizard->UnSetVar($name);
return $fileID;
}