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) || strlen($_FILES[$fileNew]["name"]) <= 0 && $deleteFile === null) { return; } if (strlen($_FILES[$fileNew]["tmp_name"]) <= 0 && $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) && strlen($arRestriction["extensions"]) > 0 ? 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 (strlen($error) > 0) { $this->SetError($error, $name . "_new"); return; } if ($make_preview && $max_width > 0 && $max_height > 0) { list($sourceWidth, $sourceHeight, $type, $attr) = CFile::GetImageSize($arFile["tmp_name"]); if ($sourceWidth > $max_width || $sourceHeight > $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 (strlen($error) > 0) { $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; }