function DoValidate($arParams, $arQuestion, $arAnswers, $arValues) { global $APPLICATION; if (count($arValues) > 0) { foreach ($arValues as $arImage) { // if image successfully uploaded if (strlen($arImage["tmp_name"]) > 0 && ($arImageInfo = CFile::GetImageSize($arImage["tmp_name"]))) { // check minimum image width if ($arParams["WIDTH_FROM"] > 0 && $arImageInfo[0] < $arParams["WIDTH_FROM"]) { $APPLICATION->ThrowException(GetMessage("FORM_VALIDATOR_IMAGE_SIZE_ERROR_WIDTH_LESS")); return false; } // check maximum image width if ($arParams["WIDTH_TO"] > 0 && $arImageInfo[0] > $arParams["WIDTH_TO"]) { $APPLICATION->ThrowException(GetMessage("FORM_VALIDATOR_IMAGE_SIZE_ERROR_WIDTH_MORE")); return false; } // check minimum image height if ($arParams["HEIGHT_FROM"] > 0 && $arImageInfo[1] < $arParams["HEIGHT_FROM"]) { $APPLICATION->ThrowException(GetMessage("FORM_VALIDATOR_IMAGE_SIZE_ERROR_HEIGHT_LESS")); return false; } // check maximum image height if ($arParams["HEIGHT_TO"] > 0 && $arImageInfo[1] > $arParams["HEIGHT_TO"]) { $APPLICATION->ThrowException(GetMessage("FORM_VALIDATOR_IMAGE_SIZE_ERROR_HEIGHT_MORE")); return false; } } } } return true; }
public static function CheckFile($arFile, $iMaxSize = 0, $iMaxWidth = 0, $iMaxHeight = 0, $access_typies = array(), $bForceMD5 = false, $bSkipExt = false) { if ($arFile["name"] == "") { return ""; } if (preg_match("#^php://filter#i", $arFile["tmp_name"])) { return GetMessage("FILE_BAD_FILE_TYPE") . ".<br>"; } $extension = GetFileExtension(strtolower($arFile["name"])); switch ($extension) { case "jpg": case "jpeg": case "gif": case "bmp": case "png": $file_type = "IMAGE"; break; case "swf": $file_type = "FLASH"; break; case "mp4": case "webm": case "ogg": $file_type = "VIDEO"; break; default: $file_type = "UNKNOWN"; } // IMAGE by default $flashEnabled = false; if (!in_array($file_type, $access_typies)) { $file_type = "IMAGE"; } if ($file_type == "FLASH") { $flashEnabled = true; static $flashMime = array("application/x-shockwave-flash", "application/vnd.adobe.flash.movie"); $res = CFile::CheckFile($arFile, $iMaxSize, $flashMime, CFile::GetFlashExtensions(), $bForceMD5, $bSkipExt); } else { if ($file_type == "VIDEO") { $res = CFile::CheckFile($arFile, $iMaxSize, "video/", "mp4,webm,ogg", $bForceMD5, $bSkipExt); } else { $res = CFile::CheckFile($arFile, $iMaxSize, "image/", CFile::GetImageExtensions(), $bForceMD5, $bSkipExt); } } if ($res != '') { return $res; } if ($file_type == 'IMAGE' || $file_type == "FLASH") { $imgArray = CFile::GetImageSize($arFile["tmp_name"], true, $flashEnabled); if (is_array($imgArray)) { $intWIDTH = $imgArray[0]; $intHEIGHT = $imgArray[1]; } else { return GetMessage("FILE_BAD_FILE_TYPE") . ".<br>"; } //check for dimensions if ($iMaxWidth > 0 && ($intWIDTH > $iMaxWidth || $intWIDTH == 0) || $iMaxHeight > 0 && ($intHEIGHT > $iMaxHeight || $intHEIGHT == 0)) { return GetMessage("FILE_BAD_MAX_RESOLUTION") . " (" . $iMaxWidth . " * " . $iMaxHeight . " " . GetMessage("main_include_dots") . ").<br>"; } } return null; }
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; }
public static function OnFileSave(&$arFile, $strFileName, $strSavePath, $bForceMD5 = false, $bSkipExt = false) { if (!$arFile["tmp_name"] && !array_key_exists("content", $arFile)) { return false; } if (array_key_exists("bucket", $arFile)) { $bucket = $arFile["bucket"]; } else { $bucket = CCloudStorage::FindBucketForFile($arFile, $strFileName); } if (!is_object($bucket)) { return false; } if (!$bucket->Init()) { return false; } $copySize = false; $subDir = ""; $filePath = ""; if (array_key_exists("content", $arFile)) { $arFile["tmp_name"] = CTempFile::GetFileName($arFile["name"]); CheckDirPath($arFile["tmp_name"]); $fp = fopen($arFile["tmp_name"], "ab"); if ($fp) { fwrite($fp, $arFile["content"]); fclose($fp); } } if (array_key_exists("bucket", $arFile)) { $newName = bx_basename($arFile["tmp_name"]); $prefix = $bucket->GetFileSRC("/"); $subDir = substr($arFile["tmp_name"], strlen($prefix)); $subDir = substr($subDir, 0, -strlen($newName) - 1); } else { if ($bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N") == "Y") { if (COption::GetOptionString("main", "convert_original_file_name", "Y") == "Y") { $newName = CCloudStorage::translit($strFileName); } else { $newName = $strFileName; } } else { $strFileExt = $bSkipExt == true ? '' : strrchr($strFileName, "."); $newName = md5(uniqid(mt_rand(), true)) . $strFileExt; } //check for double extension vulnerability $newName = RemoveScriptExtension($newName); while (true) { $strRand = md5(mt_rand()); $strRand = substr($strRand, 0, 3) . "/" . $strRand; if (substr($strSavePath, -1) == "/") { $subDir = $strSavePath . $strRand; } else { $subDir = $strSavePath . "/" . $strRand; } $subDir = ltrim($subDir, "/"); $filePath = "/" . $subDir . "/" . $newName; if (!$bucket->FileExists($filePath)) { break; } } $targetPath = $bucket->GetFileSRC("/"); if (strpos($arFile["tmp_name"], $targetPath) === 0) { $arDbFile = array("SUBDIR" => "", "FILE_NAME" => substr($arFile["tmp_name"], strlen($targetPath)), "CONTENT_TYPE" => $arFile["type"]); $copyPath = $bucket->FileCopy($arDbFile, $filePath); if (!$copyPath) { return false; } $copySize = $bucket->GetFileSize("/" . urldecode(substr($copyPath, strlen($targetPath)))); } else { $imgArray = CFile::GetImageSize($arFile["tmp_name"], true, false); if (is_array($imgArray) && $imgArray[2] == IMAGETYPE_JPEG) { $exifData = CFile::ExtractImageExif($arFile["tmp_name"]); if ($exifData && isset($exifData['Orientation'])) { $properlyOriented = CFile::ImageHandleOrientation($exifData['Orientation'], $arFile["tmp_name"]); if ($properlyOriented) { $jpgQuality = intval(COption::GetOptionString('main', 'image_resize_quality', '95')); if ($jpgQuality <= 0 || $jpgQuality > 100) { $jpgQuality = 95; } imagejpeg($properlyOriented, $arFile["tmp_name"], $jpgQuality); } } } if (!$bucket->SaveFile($filePath, $arFile)) { return false; } } } $arFile["HANDLER_ID"] = $bucket->ID; $arFile["SUBDIR"] = $subDir; $arFile["FILE_NAME"] = $newName; $arFile["WIDTH"] = 0; $arFile["HEIGHT"] = 0; if (array_key_exists("bucket", $arFile)) { $arFile["WIDTH"] = $arFile["width"]; $arFile["HEIGHT"] = $arFile["height"]; $arFile["size"] = $arFile["file_size"]; } elseif ($copySize !== false) { $arFile["size"] = $copySize; $bucket->IncFileCounter($copySize); } else { $bucket->IncFileCounter(filesize($arFile["tmp_name"])); $flashEnabled = !CFile::IsImage($arFile["ORIGINAL_NAME"], $arFile["type"]); $imgArray = CFile::GetImageSize($arFile["tmp_name"], true, $flashEnabled); if (is_array($imgArray)) { $arFile["WIDTH"] = $imgArray[0]; $arFile["HEIGHT"] = $imgArray[1]; } } if (isset($arFile["old_file"])) { CFile::DoDelete($arFile["old_file"]); } return true; }
$arResult["QUESTIONS"][$FIELD_SID]["HTML_CODE"] = implode("<br />", $arResult["QUESTIONS"][$FIELD_SID]["HTML_CODE"]); // ******************************************************************************* // if ($arResult["QUESTIONS"][$FIELD_SID]["IS_INPUT_CAPTION_IMAGE"] == "Y") { $arResult["QUESTIONS"][$FIELD_SID]["IMAGE"]["ID"] = $arResult["arQuestions"][$FIELD_SID]["IMAGE_ID"]; // assign field image path $arImage = CFile::GetFileArray($arResult["QUESTIONS"][$FIELD_SID]["IMAGE"]["ID"]); $arResult["QUESTIONS"][$FIELD_SID]["IMAGE"]["URL"] = $arImage["SRC"]; // check image file existance and assign image data if (substr($arImage["SRC"], 0, 1) == "/") { $arSize = CFile::GetImageSize($_SERVER["DOCUMENT_ROOT"].$arImage["SRC"]); if (is_array($arSize)) { list( $arResult["QUESTIONS"][$FIELD_SID]["IMAGE"]["WIDTH"], $arResult["QUESTIONS"][$FIELD_SID]["IMAGE"]["HEIGHT"], $arResult["QUESTIONS"][$FIELD_SID]["IMAGE"]["TYPE"], $arResult["QUESTIONS"][$FIELD_SID]["IMAGE"]["ATTR"] ) = $arSize; } } else { $arResult["QUESTIONS"][$FIELD_SID]["IMAGE"]["WIDTH"] = $arImage["WIDTH"]; $arResult["QUESTIONS"][$FIELD_SID]["IMAGE"]["HEIGHT"] = $arImage["HEIGHT"]; $arResult["QUESTIONS"][$FIELD_SID]["IMAGE"]["TYPE"] = false;
$arParams["PATH_TO_FONT"] = str_replace(array("\\", "//"), "/", trim($arParams["PATH_TO_FONT"])); if (file_exists($_SERVER['DOCUMENT_ROOT'] . $arParams["PATH_TO_FONT"])) { $arParams["PATH_TO_FONT"] = $_SERVER['DOCUMENT_ROOT'] . $arParams["PATH_TO_FONT"]; } else { $arParams["PATH_TO_FONT"] = str_replace(array("\\", "//"), "/", $_SERVER['DOCUMENT_ROOT'] . "/" . BX_ROOT . "/modules/photogallery/fonts/" . trim($arParams["PATH_TO_FONT"])); $arParams["PATH_TO_FONT"] = file_exists($arParams["PATH_TO_FONT"]) ? $arParams["PATH_TO_FONT"] : ""; } $arParams["WATERMARK_COLOR"] = '#' . trim($arParams["WATERMARK_COLOR"], ' #'); $arParams["WATERMARK_SIZE"] = intVal($arParams["WATERMARK_SIZE"]); $arParams["WATERMARK_FILE_REL"] = '/' . trim($arParams["WATERMARK_FILE"], ' /'); $arParams["WATERMARK_FILE"] = str_replace(array("\\", "//"), "/", $_SERVER['DOCUMENT_ROOT'] . $arParams["WATERMARK_FILE_REL"]); $arParams["WATERMARK_FILE"] = file_exists($arParams["WATERMARK_FILE"]) ? $arParams["WATERMARK_FILE"] : ""; $arParams["WATERMARK_FILE_ORDER"] = strtolower($arParams["WATERMARK_FILE_ORDER"]); $arParams["WATERMARK_POSITION"] = trim($arParams["WATERMARK_POSITION"]); if ($arParams["WATERMARK_FILE"] && CFile::IsImage($arParams["WATERMARK_FILE"])) { $imgArray = CFile::GetImageSize($arParams["WATERMARK_FILE"]); $arParams["WATERMARK_FILE_WIDTH"] = $imgArray[0]; $arParams["WATERMARK_FILE_HEIGHT"] = $imgArray[1]; } else { $arParams["WATERMARK_FILE"] = ""; $arParams["WATERMARK_FILE_REL"] = ""; } $arPositions = array("TopLeft", "TopCenter", "TopRight", "CenterLeft", "Center", "CenterRight", "BottomLeft", "BottomCenter", "BottomRight"); $arPositions2 = array("tl", "tc", "tr", "ml", "mc", "mr", "bl", "bc", "br"); if (in_array($arParams["WATERMARK_POSITION"], $arPositions2)) { $arParams["WATERMARK_POSITION"] = str_replace($arPositions2, $arPositions, $arParams["WATERMARK_POSITION"]); } else { $arParams["WATERMARK_POSITION"] = "BottomRight"; } $arParams["WATERMARK_TRANSPARENCY"] = trim($arParams["WATERMARK_TRANSPARENCY"]); $arParams["WATERMARK_MIN_PICTURE_SIZE"] = intVal($arParams["WATERMARK_MIN_PICTURE_SIZE"]) > 0 ? intVal($arParams["WATERMARK_MIN_PICTURE_SIZE"]) : 800;
if ($SMILE_TYPE == "I") { $strDirName .= "icon"; } else { $strDirName .= "smile"; } $strDirName .= "/"; $strFileName = $strFileName . "." . $strFileExt; CheckDirPath($strDirName); if (file_exists($strDirName . $strFileName) && (!$arOldSmile || $arOldSmile["SMILE_TYPE"] != $SMILE_TYPE || $arOldSmile["IMAGE"] != $strFileName)) { $strErrorMessage .= GetMessage("ERROR_EXISTS_IMAGE") . ". \n"; } else { if (!@copy($_FILES["IMAGE1"]["tmp_name"], $strDirName . $strFileName)) { $strErrorMessage .= GetMessage("ERROR_COPY_IMAGE") . ". \n"; } else { @chmod($strDirName . $strFileName, BX_FILE_PERMISSIONS); $imgArray = CFile::GetImageSize($strDirName . $strFileName); if (is_array($imgArray)) { $iIMAGE_WIDTH = $imgArray[0]; $iIMAGE_HEIGHT = $imgArray[1]; } else { $iIMAGE_WIDTH = 0; $iIMAGE_HEIGHT = 0; } } if ($arOldSmile && ($arOldSmile["SMILE_TYPE"] != $SMILE_TYPE || $arOldSmile["IMAGE"] != $strFileName) && strlen($arOldSmile["IMAGE"]) > 0) { $strDirNameOld = $_SERVER["DOCUMENT_ROOT"] . "/bitrix/images/blog/"; if ($arOldSmile["SMILE_TYPE"] == "I") { $strDirNameOld .= "icon"; } else { $strDirNameOld .= "smile"; }
:</td> <td width="60%"> <table border="0" cellspacing="0" cellpadding="0" class="internal"> <tr class="heading"> <td align="center"><?php echo GetMessage("post_file"); ?> </td> <td align="center"><?php echo GetMessage("post_size"); ?> </td> </tr> <?php foreach ($tools->aMatches as $attachment) { if (CFile::GetImageSize($attachment["PATH"], true) === false) { continue; } ?> <tr> <td><a href="<?php echo $attachment["SRC"]; ?> " target=_blank><?php echo $attachment["DEST"]; ?> </a></td> <td align="right"><?php echo filesize($attachment["PATH"]); ?> </td>
echo Number2Word_Rus($GLOBALS["SALE_INPUT_PARAMS"]["ORDER"]["SHOULD_PAY"]); } else { echo SaleFormatCurrency($GLOBALS["SALE_INPUT_PARAMS"]["ORDER"]["SHOULD_PAY"], $GLOBALS["SALE_INPUT_PARAMS"]["ORDER"]["CURRENCY"]); } ?> </p> <p> <div align="right" style="padding-right:30px;"><?php echo CSalePaySystemAction::GetParamValue("DATE_INSERT"); ?> </div><br /> <?php $stamp = CSalePaySystemAction::GetParamValue("PATH_TO_STAMP"); if (strlen($stamp) > 0) { if (file_exists($_SERVER["DOCUMENT_ROOT"] . $stamp) && is_file($_SERVER["DOCUMENT_ROOT"] . $stamp)) { list($width, $height, $type, $attr) = CFile::GetImageSize($_SERVER["DOCUMENT_ROOT"] . $stamp); ?> <img align="right" src="<?php echo $stamp; ?> " <?php echo $attr; ?> border="0" alt=""><br clear="all"><?php } } ?> </p> <p><font size="2">В случае непоступления средств на расчетный счет продавца в течение пяти банковских дней со дня выписки счета, продавец оставляет за собой право пересмотреть отпускную цену товара в рублях пропорционально изменению курса доллара
function GetContentType($path, $bPhysicalName = false) { if ($bPhysicalName) { $pathX = $path; } else { $io = CBXVirtualIo::GetInstance(); $pathX = $io->GetPhysicalName($path); } if (function_exists("mime_content_type")) { $type = mime_content_type($pathX); } else { $type = ""; } if ($type == "" && function_exists("image_type_to_mime_type")) { $arTmp = CFile::GetImageSize($pathX, true); $type = $arTmp["mime"]; } if ($type == "") { static $arTypes = array("jpeg" => "image/jpeg", "jpe" => "image/jpeg", "jpg" => "image/jpeg", "png" => "image/png", "gif" => "image/gif", "bmp" => "image/bmp", "xla" => "application/vnd.ms-excel", "xlb" => "application/vnd.ms-excel", "xlc" => "application/vnd.ms-excel", "xll" => "application/vnd.ms-excel", "xlm" => "application/vnd.ms-excel", "xls" => "application/vnd.ms-excel", "xlsx" => "application/vnd.ms-excel", "xlt" => "application/vnd.ms-excel", "xlw" => "application/vnd.ms-excel", "dbf" => "application/vnd.ms-excel", "csv" => "application/vnd.ms-excel", "doc" => "application/msword", "docx" => "application/msword", "dot" => "application/msword", "rtf" => "application/msword", "rar" => "application/x-rar-compressed", "zip" => "application/zip"); $type = $arTypes[strtolower(substr($pathX, bxstrrpos($pathX, ".") + 1))]; } if ($type == "") { $type = "application/octet-stream"; } return $type; }
function __replace_img($matches) { $src = $matches[3]; if ($src != "") { if (array_key_exists($src, $this->aMatches)) { $uid = $this->aMatches[$src]["ID"]; } elseif (file_exists($_SERVER["DOCUMENT_ROOT"] . $src) && is_array(CFile::GetImageSize($_SERVER["DOCUMENT_ROOT"] . $src))) { $dest = basename($src); $uid = uniqid(md5($dest)); $this->aMatches[$src] = array("SRC" => $src, "DEST" => $dest, "ID" => $uid); } else { return $matches[0]; } return $matches[1] . $matches[2] . "cid:" . $uid . $matches[4] . $matches[5]; } return $matches[0]; }
<td width="60%"> <table border="0" cellspacing="0" cellpadding="0" class="internal"> <tr class="heading"> <td align="center"><?php echo GetMessage("post_file"); ?> </td> <td align="center"><?php echo GetMessage("post_size"); ?> </td> </tr> <?php foreach ($tools->aMatches as $attachment) { $filename = $_SERVER["DOCUMENT_ROOT"] . $attachment["SRC"]; if (CFile::GetImageSize($filename) === false) { continue; } ?> <tr> <td><a href="<?php echo $attachment["SRC"]; ?> " target=_blank><?php echo $attachment["DEST"]; ?> </a></td> <td align="right"><?php echo filesize($filename); ?> </td>
$FILE_PERM = strlen($FILE_PERM) > 0 ? $FILE_PERM : "D"; if ($FILE_PERM >= "R") { if (CSaleAuxiliary::CheckAccess($USER->GetID(), $mp3AuxiliaryPrefix . $file, $mp3AccessTimeLength, $mp3AccessTimeType)) { $bCanAccess = True; } } } if (!$bCanAccess) { LocalRedirect($mp3Url2Folder . "auth.php?fname=" . urlencode($file) . "&DIR=" . urlencode($DIR)); } else { $filesize = filesize($filename); $f = fopen($filename, "rb"); $cur_pos = 0; $size = $filesize - 1; if ($bRealyImage) { $imageParams = CFile::GetImageSize($filename); } if ($_SERVER["REQUEST_METHOD"] == "HEAD") { if ($sapi == "cgi") { header("Status: 200 OK"); } else { header($_SERVER["SERVER_PROTOCOL"] . " 200 OK"); } header("Accept-Ranges: bytes"); header("Content-Length: " . $filesize); if ($bRealyImage) { header("Content-Type: " . $imageParams["mime"] . "; name=\"" . $file . "\""); } else { header("Content-Type: application/force-download; name=\"" . $file . "\""); } header("Last-Modified: " . date("r", filemtime($filename)));
############################################## # Bitrix: SiteManager # # Copyright (c) 2002 - 2011 Bitrix # # http://www.bitrixsoft.com # # mailto:admin@bitrixsoft.com # ############################################## */ require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"; if (CModule::IncludeModule("support") && strlen($hash) > 0) { $rsFiles = CTicket::GetFileList($v1 = "s_id", $v2 = "asc", array("HASH" => $hash)); if ($arFile = $rsFiles->Fetch()) { set_time_limit(0); if ($action == "download") { CFile::ViewByUser($arFile, array("force_download" => true)); } else { if (substr($arFile["CONTENT_TYPE"], 0, 6) === 'image/' && CFile::IsImage($arFile["FILE_NAME"], $arFile["CONTENT_TYPE"]) && (!empty($arFile["SRC"]) && CFile::GetImageSize($_SERVER["DOCUMENT_ROOT"] . $arFile["SRC"]) || $arFile["WIDTH"] > 0 && $arFile["HEIGHT"] > 0)) { CFile::ViewByUser($arFile, array("content_type" => $arFile["CONTENT_TYPE"])); } else { // check extension $ar = pathinfo($arFile["ORIGINAL_NAME"]); $ext = $ar["extension"]; switch (strtolower($ext)) { case "xla": case "xlb": case "xlc": case "xll": case "xlm": case "xls": case "xlsx": case "xlt": case "xlw":
function AddAttachment($arFields) { global $DB; $strSql = "SELECT ATTACHMENTS FROM b_mail_message WHERE ID=" . IntVal($arFields["MESSAGE_ID"]); $dbr = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if (!($dbr_arr = $dbr->Fetch())) { return false; } $n = IntVal($dbr_arr["ATTACHMENTS"]) + 1; if (strlen($arFields["FILE_NAME"]) <= 0) { $arFields["FILE_NAME"] = $n . "."; if (strpos($arFields["CONTENT_TYPE"], "message/") === 0) { $arFields["FILE_NAME"] .= "msg"; } else { $arFields["FILE_NAME"] .= "tmp"; } } if (is_set($arFields, "CONTENT_TYPE")) { $arFields["CONTENT_TYPE"] = strtolower($arFields["CONTENT_TYPE"]); } if (strpos($arFields["CONTENT_TYPE"], "image/") === 0 && (!is_set($arFields, "IMAGE_WIDTH") || !is_set($arFields, "IMAGE_HEIGHT")) && is_set($arFields, "FILE_DATA")) { $filename = CTempFile::GetFileName(md5(uniqid("")) . '.tmp'); CheckDirPath($filename); if (file_put_contents($filename, $arFields["FILE_DATA"]) !== false) { $img_arr = CFile::GetImageSize($filename); $arFields["IMAGE_WIDTH"] = $img_arr ? $img_arr[0] : 0; $arFields["IMAGE_HEIGHT"] = $img_arr ? $img_arr[1] : 0; } } if (is_set($arFields, "FILE_DATA") && !is_set($arFields, "FILE_SIZE")) { $arFields["FILE_SIZE"] = CUtil::BinStrlen($arFields["FILE_DATA"]); } if (!CMailUtil::IsSizeAllowed(strlen($DB->ForSQL($arFields["FILE_DATA"])) + 100)) { return false; } $ID = $DB->Add("b_mail_msg_attachment", $arFields, array("FILE_DATA")); if ($ID > 0) { $strSql = "UPDATE b_mail_message SET ATTACHMENTS=" . $n . " WHERE ID=" . IntVal($arFields["MESSAGE_ID"]); $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } return $ID; /* $arFile = Array( "name"=>$filename, "size"=>strlen($part["BODY"]), "type"=>$part["CONTENT-TYPE"], "content"=>$part["BODY"], "MODULE_ID"=>"mail" ); $file_id = CFile::SaveFile($arFile, "mail"); */ }
function OnFileSave(&$arFile, $strFileName, $strSavePath, $bForceMD5 = false, $bSkipExt = false) { if(!$arFile["tmp_name"] && !$arFile["content"]) return false; if(array_key_exists("bucket", $arFile)) $bucket = $arFile["bucket"]; else $bucket = CCloudStorage::FindBucketForFile($arFile, $strFileName); if(!is_object($bucket)) return false; if(!$bucket->Init()) return false; if(array_key_exists("bucket", $arFile)) { $newName = bx_basename($arFile["tmp_name"]); $prefix = $bucket->GetFileSRC("/"); $subDir = substr($arFile["tmp_name"], strlen($prefix)); $subDir = substr($subDir, 0, -strlen($newName)-1); } else { if( $bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N")=="Y" ) { if(COption::GetOptionString("main", "convert_original_file_name", "Y")=="Y") $newName = CCloudStorage::translit($strFileName); else $newName = $strFileName; } else { $strFileExt = ($bSkipExt == true? '' : strrchr($strFileName, ".")); $newName = md5(uniqid(mt_rand(), true)).$strFileExt; } //check for double extension vulnerability $newName = RemoveScriptExtension($newName); while(true) { $strRand = md5(mt_rand()); $strRand = substr($strRand, 0, 3)."/".$strRand; if(substr($strSavePath, -1) == "/") $subDir = $strSavePath.$strRand; else $subDir = $strSavePath."/".$strRand; $subDir = ltrim($subDir, "/"); $filePath = "/".$subDir."/".$newName; if(!$bucket->FileExists($filePath)) break; } if(!$bucket->SaveFile($filePath, $arFile)) return false; } $arFile["HANDLER_ID"] = $bucket->ID; $arFile["SUBDIR"] = $subDir; $arFile["FILE_NAME"] = $newName; $arFile["WIDTH"] = 0; $arFile["HEIGHT"] = 0; if(array_key_exists("bucket", $arFile)) { $arFile["WIDTH"] = $arFile["width"]; $arFile["HEIGHT"] = $arFile["height"]; $arFile["size"] = $arFile["file_size"]; } elseif(array_key_exists("content", $arFile)) { $tmp_name = tempnam(); $fp = fopen($tmp_name, "ab"); if($fp) { if(fwrite($fp, $arFile["content"])) { $bucket->IncFileCounter(filesize($tmp_name)); $imgArray = CFile::GetImageSize($tmp_name); if(is_array($imgArray)) { $arFile["WIDTH"] = $imgArray[0]; $arFile["HEIGHT"] = $imgArray[1]; } } fclose($fp); unlink($tmp_name); } } else { $bucket->IncFileCounter(filesize($arFile["tmp_name"])); $imgArray = CFile::GetImageSize($arFile["tmp_name"]); if(is_array($imgArray)) { $arFile["WIDTH"] = $imgArray[0]; $arFile["HEIGHT"] = $imgArray[1]; } } if(isset($arFile["old_file"])) CFile::DoDelete($arFile["old_file"]); return true; }
function handleFile($Info, $arFiles, $Params) { CModule::IncludeModule("iblock"); global $USER; $arParams = $Params['arParams']; $savedData = CImageUploader::GetSavedData(); $arErrors = array(); // Check file sizes and types (types only for mass uploaders) foreach ($arFiles as $file) { if ($file['size'] > 0 && $arParams["UPLOAD_MAX_FILE_SIZE"] > 0 && $file['size'] > $arParams["UPLOAD_MAX_FILE_SIZE"]) { $arErrors[] = array("file" => $file['name'], "id" => "BXPH_FUNC_HANDLE_2_LARGE_SIZE", "text" => GetMessage('P_WM_IMG_ERROR04')); } if ($file['type'] && strpos(strtolower($file['type']), 'image') === false) { $arErrors[] = array("file" => $file['name'], "id" => "BXPH_FUNC_HANDLE_2_TYPE", "text" => GetMessage('P_WM_IMG_ERROR02')); } } if (count($arErrors) > 0) { // Exit if we have any errors return CImageUploader::SaveError($arErrors); } // Handle watermark for Flash-uploader if ($arParams["UPLOADER_TYPE"] == 'flash') { $arWatermark = false; if ($arParams['WATERMARK_RULES'] == 'ALL') { $arWatermark = array('type' => strtolower($arParams['WATERMARK_TYPE']), 'position' => $arParams['WATERMARK_POSITION']); if ($arParams['WATERMARK_TYPE'] == 'TEXT') { $arWatermark['coefficient'] = $arParams['WATERMARK_SIZE']; $arWatermark['text'] = trim($arParams['WATERMARK_TEXT']); $arWatermark['font'] = trim($arParams['PATH_TO_FONT']); $arWatermark['color'] = trim($arParams['WATERMARK_COLOR']); $arWatermark['use_copyright'] = "N"; } else { $arWatermark['file'] = $arParams['WATERMARK_FILE']; $arWatermark['alpha_level'] = $arParams['WATERMARK_TRANSPARENCY']; $arWatermark['size'] = 'real'; $arWatermark['fill'] = $arParams['WATERMARK_FILE_ORDER'] == 'usual' ? 'exact' : $arParams['WATERMARK_FILE_ORDER']; } } elseif ($Params['packageFields']['photo_watermark_use'] == 'Y') { $arWatermark = array('type' => $Params['packageFields']['photo_watermark_type'], 'text' => $Params['packageFields']['photo_watermark_text'], 'font' => $arParams['PATH_TO_FONT'], 'position' => $Params['packageFields']['photo_watermark_position'], 'color' => $Params['packageFields']['photo_watermark_color'], 'size' => $Params['packageFields']['photo_watermark_size'], 'fill' => 'resize', 'file' => $_SERVER["DOCUMENT_ROOT"] . $Params['packageFields']['photo_watermark_path'], 'alpha_level' => $Params['packageFields']['photo_watermark_opacity'], 'use_copyright' => $Params['packageFields']["photo_watermark_copyright"] == "Y" ? "Y" : "N"); } if ($arWatermark) { // Add watermark here foreach ($arFiles as $i => $file) { if ($i == 1) { // It's thumbnail skip it continue; } $size = CFile::GetImageSize($file['tmp_name']); $type = $size[2]; $sourceImage = CFile::CreateImage($file['tmp_name'], $type); if ($sourceImage) { $res = CFile::Watermark($sourceImage, $arWatermark); if (file_exists($file['tmp_name'])) { unlink($file['tmp_name']); } switch ($type) { case IMAGETYPE_GIF: imagegif($sourceImage, $file['tmp_name']); break; case IMAGETYPE_PNG: imagealphablending($sourceImage, false); imagesavealpha($sourceImage, true); imagepng($sourceImage, $file['tmp_name']); break; default: if ($arSourceFileSizeTmp[2] == IMAGETYPE_BMP) { $file['tmp_name'] .= ".jpg"; } imagejpeg($sourceImage, $file['tmp_name'], 100); break; } if ($sourceImage) { imagedestroy($sourceImage); } } } } } // Props $Prop = array(); // Additional image copyies $ind = -1; foreach ($arParams['converters'] as $key => $val) { $ind++; if ($val['code'] == "real_picture" || $val['code'] == "thumbnail") { continue; } $Prop[strtoupper($val['code'])] = array("n0" => $arFiles[$ind]); } $_REQUEST["Public"] = $_REQUEST["Public"] == "N" ? "N" : "Y"; $Prop["PUBLIC_ELEMENT"] = array("n0" => $_REQUEST["Public"]); $Prop["APPROVE_ELEMENT"] = array("n0" => ($arParams["ABS_PERMISSION"] >= "U" || $arParams["APPROVE_BY_DEFAULT"] == "Y") && $_REQUEST["Public"] == "Y" ? "Y" : "X"); // Real photo $Prop["REAL_PICTURE"] = array("n0" => $arFiles[0]); $arFields = array("ACTIVE" => $arParams["MODERATION"] == "Y" && $arParams["ABS_PERMISSION"] < "U" ? "N" : "Y", "MODIFIED_BY" => $USER->GetID(), "IBLOCK_SECTION" => $savedData['SECTION_ID'], "IBLOCK_ID" => $arParams["IBLOCK_ID"], "NAME" => $Info['name'], "CODE" => $Info['name'], "TAGS" => $Info['tags'], "DETAIL_TEXT" => $Info['description'], "DETAIL_TEXT_TYPE" => "text", "PREVIEW_PICTURE" => $arFiles[1], "PREVIEW_TEXT" => $Info['description'], "PREVIEW_TEXT_TYPE" => "text", "PROPERTY_VALUES" => $Prop); //$arFields["NAME"] = (!empty($arFields["NAME"]) ? $arFields["NAME"] : $File["REAL_PICTURE"]["name"]); //$arFields["DATE_CREATE"] = (intVal($arRealFile["ExifTimeStamp"]) > 0 ? // ConvertTimeStamp($arRealFile["ExifTimeStamp"], "FULL") : $arFields["DATE_CREATE"]); $bs = new CIBlockElement(); $ID = $bs->Add($arFields); if ($ID <= 0) { $strError = $bs->LAST_ERROR; $arErrors = array(); $arTmp = explode("<br>", $strError); foreach ($arTmp as $er) { if (trim($er) != '' && !in_array($er, $arErrors)) { $arErrors[] = array("id" => "BXPH_FUNC_002", "text" => $er); } } CImageUploader::SaveError($arErrors); } else { $arFields['ID'] = $ID; $_SESSION['arUploadedPhotos'][] = $ID; CIBlockElement::RecalcSections($ID); $arParams['SECTION_ID'] = $savedData['SECTION_ID']; $arResult = $Params['~arResult']; foreach (GetModuleEvents("photogallery", "OnAfterUpload", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arFields, $arParams, $arResult)); } // Add thumbnail only for new album if ($savedData['NEW_SECTION_NAME'] && !$savedData['NEW_SECTION_PICTURE']) { $File = $arFiles[0]; // Big picture $File['tmp_name_1'] = $File['tmp_name']; $File['tmp_name'] = substr($File['tmp_name'], 0, strrpos($File['tmp_name'], ".")) . "_album_cover.tmp"; if (CFile::ResizeImageFile($File['tmp_name_1'], $File['tmp_name'], array('width' => $arParams["ALBUM_PHOTO_THUMBS"]["SIZE"], 'height' => $arParams["ALBUM_PHOTO_THUMBS"]["SIZE"]), BX_RESIZE_IMAGE_PROPORTIONAL)) { $bs = new CIBlockSection(); if ($bs->Update($savedData["SECTION_ID"], array("PICTURE" => $File), false, false)) { $savedData['NEW_SECTION_PICTURE'] = true; CImageUploader::SetSavedData($savedData); } } } } return $ID; }
} elseif (ForumCurrUserPermissions($arResult["MESSAGE"]["FORUM_ID"]) < "E") { $arError = array("code" => "NOT RIGHT", "title" => GetMessage("F_NOT_RIGHT")); } } if (!empty($arError)) { require $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/prolog_after.php"; echo ShowError(!empty($arError["title"]) ? $arError["title"] : $arError["code"]); require $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/epilog.php"; die; } // *************************/Default params************************************************************* set_time_limit(0); if ($arParams["ACTION"] == "download") { CFile::ViewByUser($arResult["FILE"], array("force_download" => true)); } else { if (CFile::CheckImageFile(CFile::MakeFileArray($arResult["FILE"]["FILE_ID"])) === null && (file_exists($_SERVER["DOCUMENT_ROOT"] . $arResult["FILE"]["SRC"]) && CFile::GetImageSize($_SERVER["DOCUMENT_ROOT"] . $arResult["FILE"]["SRC"]) || $arResult["FILE"]["WIDTH"] > 0 && $arResult["FILE"]["HEIGHT"] > 0)) { if ($arParams['WIDTH'] > 0 && $arParams['HEIGHT'] > 0) { $imageFile = $arResult['FILE']; $arFileTmp = CFile::ResizeImageGet($imageFile, array("width" => $arParams["WIDTH"], "height" => $arParams["HEIGHT"]), BX_RESIZE_IMAGE_PROPORTIONAL, true); $imageFile["FILE_SIZE"] = $arFileTmp['size']; $imageFile["SRC"] = $arFileTmp['src']; CFile::ViewByUser($imageFile, array("content_type" => $arResult["FILE"]["CONTENT_TYPE"])); } else { CFile::ViewByUser($arResult["FILE"], array("content_type" => $arResult["FILE"]["CONTENT_TYPE"])); } } else { $ct = strtolower($arResult["FILE"]["CONTENT_TYPE"]); if (strpos($ct, "excel") !== false) { CFile::ViewByUser($arResult["FILE"], array("content_type" => "application/vnd.ms-excel")); } elseif (strpos($ct, "word") !== false) { CFile::ViewByUser($arResult["FILE"], array("content_type" => "application/msword"));
public static function import($arParams) { global $APPLICATION; // check fields $aMsg = array(); $arParams['SET_ID'] = intval($arParams['SET_ID']); $arParams['IMPORT_IF_FILE_EXISTS'] = isset($arParams['IMPORT_IF_FILE_EXISTS']) && $arParams['IMPORT_IF_FILE_EXISTS'] == 'Y' ? true : false; if (isset($arParams['FILE']) && GetFileExtension($arParams['FILE']) != 'zip') { $aMsg["FILE_EXT"] = array("id" => "FILE_EXT", "text" => GetMessage("MAIN_SMILE_IMPORT_FILE_EXT_ERROR")); } else { if (!isset($arParams['FILE']) || !file_exists($arParams['FILE'])) { $aMsg["FILE"] = array("id" => "FILE", "text" => GetMessage("MAIN_SMILE_IMPORT_FILE_ERROR")); } else { if ($arParams['SET_ID'] <= 0) { $aMsg["SET_ID"] = array("id" => "SET_ID", "text" => GetMessage("MAIN_SMILE_IMPORT_SET_ID_ERROR")); } } } if (!empty($aMsg)) { $e = new CAdminException($aMsg); $APPLICATION->ThrowException($e); return false; } $sUnpackDir = CTempFile::GetDirectoryName(1); CheckDirPath($sUnpackDir); /** @var IBXArchive $oArchiver */ $oArchiver = CBXArchive::GetArchive($arParams['FILE'], "ZIP"); $oArchiver->SetOptions(array("STEP_TIME" => 300)); if (!$oArchiver->Unpack($sUnpackDir)) { $aMsg["UNPACK"] = array("id" => "UNPACK", "text" => GetMessage("MAIN_SMILE_IMPORT_UNPACK_ERROR")); $e = new CAdminException($aMsg); $APPLICATION->ThrowException($e); return false; } $arSmiles = array(); if (file_exists($sUnpackDir . 'install.csv')) { $arLang = array(); $db_res = CLanguage::GetList($b = "sort", $o = "asc"); while ($res = $db_res->Fetch()) { if (file_exists($sUnpackDir . 'install_lang_' . $res["LID"] . '.csv')) { $arSmiles = array(); $csvFile = new CCSVData(); $csvFile->LoadFile($sUnpackDir . 'install_lang_' . $res["LID"] . '.csv'); $csvFile->SetFieldsType("R"); $csvFile->SetFirstHeader(false); while ($smile = $csvFile->Fetch()) { if (defined('BX_UTF') && BX_UTF && $res["LID"] == 'ru') { $smile[1] = $APPLICATION->ConvertCharset($smile[1], 'windows-1251', 'utf-8'); } $arLang[$smile[0]][$res["LID"]] = $smile[1]; } } } $csvFile = new CCSVData(); $csvFile->LoadFile($sUnpackDir . 'install.csv'); $csvFile->SetFieldsType("R"); $csvFile->SetFirstHeader(false); while ($smileRes = $csvFile->Fetch()) { $smile = array('TYPE' => $smileRes[0], 'CLICKABLE' => $smileRes[1] == 'Y' ? 'Y' : 'N', 'SORT' => intval($smileRes[2]), 'IMAGE' => $smileRes[3], 'IMAGE_WIDTH' => intval($smileRes[4]), 'IMAGE_HEIGHT' => intval($smileRes[5]), 'IMAGE_DEFINITION' => in_array($smileRes[6], array(self::IMAGE_SD, self::IMAGE_HD, self::IMAGE_UHD)) ? $smileRes[6] : ($smileRes[6] == 'Y' ? self::IMAGE_HD : self::IMAGE_SD), 'HIDDEN' => in_array($smileRes[7], array('Y', 'N')) ? $smileRes[7] : 'N', 'IMAGE_LANG' => in_array($smileRes[7], array('Y', 'N')) ? $smileRes[8] : $smileRes[7], 'TYPING' => in_array($smileRes[7], array('Y', 'N')) ? $smileRes[9] : $smileRes[8]); if (!in_array($smile['TYPE'], array(CSmile::TYPE_SMILE, CSmile::TYPE_ICON))) { continue; } $smile['IMAGE'] = GetFileName($smile['IMAGE']); $imgArray = CFile::GetImageSize($sUnpackDir . $smile['IMAGE']); if (!is_array($imgArray)) { continue; } $arInsert = array('TYPE' => $smile['TYPE'], 'SET_ID' => $arParams['SET_ID'], 'CLICKABLE' => $smile['CLICKABLE'], 'SORT' => $smile['SORT'], 'IMAGE' => $smile['IMAGE'], 'IMAGE_WIDTH' => $smile['IMAGE_WIDTH'], 'IMAGE_HEIGHT' => $smile['IMAGE_HEIGHT'], 'IMAGE_DEFINITION' => $smile['IMAGE_DEFINITION'], 'HIDDEN' => $smile['HIDDEN'], 'TYPING' => $smile['TYPING']); if (isset($arLang[$smile['IMAGE_LANG']])) { $arInsert['LANG'] = $arLang[$smile['IMAGE_LANG']]; } $arSmiles[] = $arInsert; } } else { $smileSet = CSmileSet::getById($arParams['SET_ID']); if ($handle = @opendir($sUnpackDir)) { $sort = 300; while (($file = readdir($handle)) !== false) { if ($file == "." || $file == "..") { continue; } if (is_file($sUnpackDir . $file)) { $imgArray = CFile::GetImageSize($sUnpackDir . $file); if (is_array($imgArray)) { $smileHR = self::IMAGE_SD; $smileType = CSmile::TYPE_SMILE; $smileCode = GetFileNameWithoutExtension($file); if (strpos($file, 'smile_') !== false && strpos($file, 'smile_') == 0) { $smileCode = substr($smileCode, 6); } elseif (strpos($file, 'smile') !== false && strpos($file, 'smile') == 0) { $smileCode = substr($smileCode, 5); } elseif (strpos($file, 'icon_') !== false && strpos($file, 'icon_') == 0) { $smileType = CSmile::TYPE_ICON; $smileCode = substr($smileCode, 5); } else { if (strpos($file, 'icon') !== false && strpos($file, 'icon') == 0) { $smileType = CSmile::TYPE_ICON; $smileCode = substr($smileCode, 4); } } if (strrpos($smileCode, '_hr') !== false && strrpos($smileCode, '_hr') == strlen($smileCode) - 3) { $smileHR = self::IMAGE_HD; $smileCode = substr($smileCode, 0, strrpos($smileCode, '_hr')); } if ($pos = strpos($smileCode, '_hr_')) { $smileHR = self::IMAGE_HD; $smileCode = substr($smileCode, 0, $pos) . '_' . substr($smileCode, $pos + 4); } $arSmiles[] = array('TYPE' => $smileType, 'SET_ID' => $arParams['SET_ID'], 'CLICKABLE' => 'Y', 'SORT' => $sort, 'IMAGE' => $file, 'IMAGE_WIDTH' => intval($imgArray[0]), 'IMAGE_HEIGHT' => intval($imgArray[1]), 'IMAGE_DEFINITION' => $smileHR, 'TYPING' => ':' . (isset($smileSet['STRING_ID']) ? $smileSet['STRING_ID'] : $smileSet['ID']) . '/' . $smileCode . ':'); $sort = $sort + 5; } } } @closedir($handle); } } $importSmile = 0; foreach ($arSmiles as $smile) { $sUploadDir = ($smile['TYPE'] == CSmile::TYPE_ICON ? CSmile::PATH_TO_ICON : CSmile::PATH_TO_SMILE) . intval($smile["SET_ID"]) . '/'; if (file_exists($sUnpackDir . $smile['IMAGE']) && ($arParams['IMPORT_IF_FILE_EXISTS'] || !file_exists($_SERVER["DOCUMENT_ROOT"] . $sUploadDir . $smile['IMAGE']))) { if (CheckDirPath($_SERVER["DOCUMENT_ROOT"] . $sUploadDir)) { $insertId = CSmile::add($smile); if ($insertId) { if ($arParams['IMPORT_IF_FILE_EXISTS'] && file_exists($_SERVER["DOCUMENT_ROOT"] . $sUploadDir . $smile['IMAGE'])) { $importSmile++; } else { if (copy($sUnpackDir . $smile['IMAGE'], $_SERVER["DOCUMENT_ROOT"] . $sUploadDir . $smile['IMAGE'])) { @chmod($_SERVER["DOCUMENT_ROOT"] . $sUploadDir . $smile['IMAGE'], BX_FILE_PERMISSIONS); $importSmile++; } else { CSmile::delete($insertId); } } } $APPLICATION->ResetException(); } } } return $importSmile; }
public static function CheckFields($ACTION, &$arFields) { $aMsg = array(); if ((is_set($arFields, "TYPE") || $ACTION == "ADD") && $arFields["TYPE"] != "I" && $arFields["TYPE"] != "S") { if (empty($arFields["TYPE"])) { $aMsg[] = array("id" => "TYPE", "text" => GetMessage("FS_ERROR_EMPTY_TYPE")); } else { $aMsg[] = array("id" => "TYPE", "text" => GetMessage("FS_ERROR_UNKNOWN_TYPE", array("#TYPE#" => $arFields["TYPE"]))); } } if (is_set($arFields, "TYPING") && !empty($arFields["TYPING"])) { if (preg_match("/[\\<\\>\"\\']/is", $arFields["TYPING"]) != false) { $aMsg[] = array("id" => "TYPING", "text" => GetMessage("FS_ERROR_TYPING")); } } if ((is_set($arFields, "IMAGE") || $ACTION == "ADD") && empty($arFields["IMAGE"])) { $aMsg[] = array("id" => "IMAGE", "text" => GetMessage("FS_ERROR_EMPTY_IMAGE")); } elseif (is_set($arFields, "IMAGE")) { $arFile = CFile::GetImageSize($_SERVER['DOCUMENT_ROOT'] . BX_ROOT . "/images/forum/" . ($arFields["TYPE"] == "I" ? "icon" : "smile") . "/" . $arFields["IMAGE"]); $arFile = is_array($arFile) ? $arFile : array(); $arFile = array("name" => $arFields["IMAGE"], "tmp_name" => $_SERVER['DOCUMENT_ROOT'] . BX_ROOT . "/images/forum/" . ($arFields["TYPE"] == "I" ? "icon" : "smile") . "/" . $arFields["IMAGE"], "type" => $arFile["mime"], "size" => @filesize($_SERVER['DOCUMENT_ROOT'] . BX_ROOT . "/images/forum/" . ($arFields["TYPE"] == "I" ? "icon" : "smile") . "/" . $arFields["IMAGE"]), "error" => 0, "width" => $arFile[0], "height" => $arFile[1]); $res = CFile::CheckImageFile($arFile, COption::GetOptionString("forum", "file_max_size", 5242880)); if (strLen($res) > 0) { $aMsg[] = array("id" => "IMAGE", "text" => $res); } else { $arFields["IMAGE_WIDTH"] = $arFile["width"]; $arFields["IMAGE_HEIGHT"] = $arFile["height"]; } } if (is_set($arFields, "LANG") || $ACTION == "ADD") { $res = is_array($arFields["LANG"]) ? $arFields["LANG"] : array(); foreach ($res as $i => $val) { if (empty($res[$i]["LID"]) || empty($res[$i]["NAME"])) { unset($res[$i]); } } $db_lang = CLanguage::GetList($b = "sort", $o = "asc"); while ($arLang = $db_lang->Fetch()) { $bFound = false; foreach ($res as $i => $val) { if ($res[$i]["LID"] == $arLang["LID"]) { $bFound = true; } } if (!$bFound) { $aMsg[] = array("id" => 'NAME_' . $arLang["LID"], "text" => GetMessage("FS_ERROR_EMPTY_NAME", array("#LID#" => $arLang["LID"], "#LID_NAME#" => $arLang["NAME"]))); } } } if ((is_set($arFields, "SORT") || $ACTION == "ADD") && intVal($arFields["SORT"]) <= 0) { $arFields["SORT"] = 150; } if (!empty($aMsg)) { $e = new CAdminException(array_reverse($aMsg)); $GLOBALS["APPLICATION"]->ThrowException($e); return false; } return true; }
public static function FilterPicture($filePath, $arFilter) { if (!file_exists($filePath)) return false; $arFileSize = CFile::GetImageSize($filePath, true); if(!is_array($arFileSize)) return false; if ($arFilter["type"] === "text" && strlen($arFilter["text"]) > 1 && $arFilter["coefficient"] > 0) { $arFilter["text_width"] = ($arFileSize[0]-5) * $arFilter["coefficient"] / 100; } switch ($arFileSize[2]) { case IMAGETYPE_GIF: $picture = imagecreatefromgif($filePath); $bHasAlpha = true; break; case IMAGETYPE_PNG: $picture = imagecreatefrompng($filePath); $bHasAlpha = true; break; case IMAGETYPE_JPEG: $picture = imagecreatefromjpeg($filePath); $orientation = 0; $exifData = CFile::ExtractImageExif($filePath); if ($exifData && isset($exifData['Orientation'])) { $orientation = $exifData['Orientation']; } if ($orientation > 1) { if ($orientation == 7 || $orientation == 8) $picture = imagerotate($picture, 90, null); elseif ($orientation == 3 || $orientation == 4) $picture = imagerotate($picture, 180, null); elseif ($orientation == 5 || $orientation == 6) $picture = imagerotate($picture, 270, null); if ( $orientation == 2 || $orientation == 7 || $orientation == 4 || $orientation == 5 ) { CFile::ImageFlipHorizontal($picture); } } $bHasAlpha = false; break; default: $picture = false; $bHasAlpha = false; break; } if (!is_resource($picture)) return false; $bNeedCreatePicture = CFile::ApplyImageFilter($picture, $arFilter, $bHasAlpha); if ($bNeedCreatePicture) { switch ($arFileSize[2]) { case IMAGETYPE_GIF: imagegif($picture, $filePath); break; case IMAGETYPE_PNG: imagealphablending($picture, false); imagesavealpha($picture, true); imagepng($picture, $filePath); break; case IMAGETYPE_JPEG: $jpgQuality = intval(COption::GetOptionString('main', 'image_resize_quality', '95')); if ($jpgQuality <= 0 || $jpgQuality > 100) $jpgQuality = 95; imagejpeg($picture, $filePath, $jpgQuality); break; } } imagedestroy($picture); return true; }
public function GetImageSize($file) { $height = 0; $width = 0; if (intval($file) > 0) { $arFile = CFile::GetFileArray($file); if ($arFile) { $height = $arFile['HEIGHT'] * 0.75; $width = $arFile['WIDTH'] * 0.75; } } else { $arFile = CFile::GetImageSize($this->GetImagePath($file), true); if ($arFile) { $height = $arFile[0] * 0.75; $width = $arFile[1] * 0.75; } } return array(0 => $height, 1 => $width); }
public static function FilterPicture($filePath, $arFilter) { if (!file_exists($filePath)) { return false; } $arFileSize = CFile::GetImageSize($filePath, true); if (!is_array($arFileSize)) { return false; } switch ($arFileSize[2]) { case IMAGETYPE_GIF: $picture = imagecreatefromgif($filePath); $bHasAlpha = true; break; case IMAGETYPE_PNG: $picture = imagecreatefrompng($filePath); $bHasAlpha = true; break; case IMAGETYPE_JPEG: $picture = imagecreatefromjpeg($filePath); $bHasAlpha = false; break; default: $picture = false; $bHasAlpha = false; break; } if (!is_resource($picture)) { return false; } $bNeedCreatePicture = CFile::ApplyImageFilter($picture, $arFilter, $bHasAlpha); if ($bNeedCreatePicture) { switch ($arFileSize[2]) { case IMAGETYPE_GIF: imagegif($picture, $filePath); break; case IMAGETYPE_PNG: imagealphablending($picture, false); imagesavealpha($picture, true); imagepng($picture, $filePath); break; case IMAGETYPE_JPEG: $jpgQuality = intval(COption::GetOptionString('main', 'image_resize_quality', '95')); if ($jpgQuality <= 0 || $jpgQuality > 100) { $jpgQuality = 95; } imagejpeg($picture, $filePath, $jpgQuality); break; } } imagedestroy($picture); return true; }
private static function GetFile($fileId = "") { $arFile = CFile::GetFileArray($fileId); $io = CBXVirtualIo::GetInstance(); //Check if not ID but file path was given if (!is_array($arFile) && $fileId != "") { $strFilePath = $_SERVER["DOCUMENT_ROOT"] . $fileId; if ($io->FileExists($strFilePath)) { $flTmp = $io->GetFile($strFilePath); $arFile = array("PATH" => $fileId, "FILE_SIZE" => $flTmp->GetFileSize(), "DESCRIPTION" => ""); $arImageSize = CFile::GetImageSize($strFilePath); if (is_array($arImageSize)) { $arFile["WIDTH"] = intval($arImageSize[0]); $arFile["HEIGHT"] = intval($arImageSize[1]); } } elseif (self::$showInfo['IMAGE'] == 'N') { $arFile = array("PATH" => $fileId, "FORMATED_SIZE" => '', "DESCRIPTION" => "", "IS_IMAGE" => false); return $arFile; } } $sImagePath = isset($arFile["PATH"]) ? $arFile["PATH"] : $arFile["SRC"]; if ($arFile["HANDLER_ID"] || defined("BX_IMG_SERVER") && substr($sImagePath, 0, strlen(BX_IMG_SERVER)) === BX_IMG_SERVER || $io->FileExists($_SERVER["DOCUMENT_ROOT"] . $sImagePath)) { $arFile["FORMATED_SIZE"] = CFile::FormatSize($arFile["FILE_SIZE"]); $arFile["IS_IMAGE"] = $arFile["WIDTH"] > 0 && $arFile["HEIGHT"] > 0 && self::$showInfo['IMAGE'] != 'N'; unset($arFile["MODULE_ID"], $arFile["CONTENT_TYPE"], $arFile["SUBDIR"], $arFile["~src"]); return $arFile; } return false; }
protected function _MakeFields(&$arFields, $itemType = null) { $arRes = array(); $upload_dir = COption::GetOptionString("main", "upload_dir", "upload"); $arStopList = array(); foreach ($arFields["#"] as $field => $arValue) { if (in_array($field, $arStopList)) { continue; } if (in_array($field, $this->arUnsetFields) && $itemType !== 'TMK' && $itemType !== 'QUE') { if (!($itemType === 'TES' && in_array($field, $this->arPreventUnsetFieldsForTest))) { continue; } } if (in_array($field, $this->arDraftFields) && $itemType !== 'TMK') { if (is_set($arValue[0]["#"], "cdata-section")) { $arRes[strtoupper($field)] = preg_replace("~([\"'])(cid:resources/(.+?))(\\1)~is", "\\1/" . $upload_dir . "/learning/" . $this->COURSE_ID . "/\\3\\1", $arValue[0]["#"]["cdata-section"][0]["#"]); continue; } elseif (isset($arValue[0]["#"])) { $arRes[strtoupper($field)] = preg_replace("~([\"'])(cid:resources/(.+?))(\\1)~is", "\\1/" . $upload_dir . "/learning/" . $this->COURSE_ID . "/\\3\\1", $arValue[0]["#"]); continue; } } if (in_array($field, $this->arDate) && strlen($arValue[0]["#"]) > 0) { $time = date("His", $arValue[0]["#"]); $arRes[strtoupper($field)] = ConvertTimeStamp($arValue[0]["#"], $time == "000000" ? "SHORT" : "FULL"); continue; } if (in_array($field, $this->arPicture) && intval($arValue[0]["#"]) > 0) { $file = $this->package_dir . "/dbresources/" . $arValue[0]["#"]; if (method_exists('CFile', 'GetImageSize')) { $aImage = @CFile::GetImageSize($file); if ($aImage === false) { continue; } if (function_exists("image_type_to_mime_type")) { $image_type_to_mime_type = image_type_to_mime_type($aImage[2]); } else { $image_type_to_mime_type = CCourseImport::ImageTypeToMimeType($aImage[2]); } } else { $image_type_to_mime_type = self::ImageTypeToMimeTypeByFileName($file); } $arRes[strtoupper($field)] = array("MODULE_ID" => "learning", "name" => $arValue[0]["#"], "tmp_name" => $file, "size" => @filesize($file), "type" => $image_type_to_mime_type); if (isset($arFields["#"][$field . '_description'][0]['#'])) { $arRes[strtoupper($field)]['description'] = $arFields["#"][$field . '_description'][0]['#']; $arStopList[] = $field . '_description'; } continue; } $arRes[strtoupper($field)] = $arValue[0]["#"]; } unset($arFields); return $arRes; }
private function GetVCardContent(array $contact) { $arVCardContact = array("TYPE" => "VCARD", "VERSION" => "3.0", "N" => $contact["LAST_NAME"] . ";" . $contact["NAME"] . ";" . $contact["SECOND_NAME"] . ";;", "FN" => $contact["NAME"] . ($contact["SECOND_NAME"] ? " " . $contact["SECOND_NAME"] : "") . " " . $contact["LAST_NAME"], "EMAIL" => array("VALUE" => $contact["EMAIL"], "PARAMETERS" => array("TYPE" => "INTERNET")), "REV" => date("Ymd\\THis\\Z", MakeTimeStamp($contact["TIMESTAMP_X"])), "UID" => $contact["ID"]); if (intval($contact["PERSONAL_BIRTHDAY"]) > 0) { $arVCardContact["BDAY"] = date("Y-m-d", MakeTimeStamp($contact["PERSONAL_BIRTHDAY"])); } if (strlen($contact["WORK_PHONE"]) > 0) { $arVCardContact["TEL"][] = array("VALUE" => $contact["WORK_PHONE"], "PARAMETERS" => array("TYPE" => "WORK")); } if (strlen($contact["PERSONAL_MOBILE"]) > 0) { $arVCardContact["TEL"][] = array("VALUE" => $contact["PERSONAL_MOBILE"], "PARAMETERS" => array("TYPE" => "CELL")); } if (strlen($contact["PERSONAL_PHONE"]) > 0) { $arVCardContact["TEL"][] = array("VALUE" => $contact["PERSONAL_PHONE"], "PARAMETERS" => array("TYPE" => "HOME")); } if (strlen($contact["WORK_COMPANY"]) > 0) { $arVCardContact["ORG"] = $contact["WORK_COMPANY"]; } if (strlen($contact["WORK_POSITION"]) > 0) { $arVCardContact["TITLE"] = $contact["WORK_POSITION"]; } if (strlen($contact["WORK_WWW"]) > 0) { $arVCardContact["URL"][] = array("VALUE" => $contact["WORK_WWW"], "PARAMETERS" => array("TYPE" => "WORK")); } if (strlen($contact["PERSONAL_WWW"]) > 0) { $arVCardContact["URL"][] = array("VALUE" => $contact["PERSONAL_WWW"], "PARAMETERS" => array("TYPE" => "HOME")); } if (strlen($contact["PERSONAL_STREET"]) > 0) { $arVCardContact["ADR"][] = array("VALUE" => ";;" . $contact["PERSONAL_STREET"] . ";" . $contact["PERSONAL_CITY"] . ";" . $contact["PERSONAL_STATE"] . ";" . $contact["PERSONAL_ZIP"] . ";" . GetCountryByID($contact["PERSONAL_COUNTRY"]) . "", "PARAMETERS" => array("TYPE" => "HOME")); } if (strlen($contact["WORK_STREET"]) > 0) { $arVCardContact["ADR"][] = array("VALUE" => ";;" . $contact["WORK_STREET"] . ";" . $contact["WORK_CITY"] . ";" . $contact["WORK_STATE"] . ";" . $contact["WORK_ZIP"] . ";" . GetCountryByID($contact["WORK_COUNTRY"]) . "", "PARAMETERS" => array("TYPE" => "WORK")); } if (intval($contact["PERSONAL_PHOTO"]) > 0) { $arTempFile = CFile::ResizeImageGet($contact["PERSONAL_PHOTO"], array("width" => \Bitrix\Main\Config\Option::get("dav", "vcard_image_width", 400), "height" => \Bitrix\Main\Config\Option::get("dav", "vcard_image_width", 400)), BX_RESIZE_IMAGE_PROPORTIONAL, false, false, false, \Bitrix\Main\Config\Option::get("dav", "vcard_image_quality", 60)); if ($arTempFile) { $cnt = file_get_contents($_SERVER["DOCUMENT_ROOT"] . $arTempFile['src']); if (!empty($cnt)) { $arImageTypes = array(IMAGETYPE_JPEG => 'JPEG', IMAGETYPE_GIF => 'GIF', IMAGETYPE_PNG => 'PNG'); $imageType = "JPEG"; if ($imageInfo = CFile::GetImageSize($_SERVER["DOCUMENT_ROOT"] . $arTempFile['src']) && isset($arImageTypes[$imageInfo[2]])) { $imageType = $arImageTypes[$imageInfo[2]]; } $arVCardContact["PHOTO"] = array("VALUE" => base64_encode($cnt), "PARAMETERS" => array("ENCODING" => "BASE64", "TYPE" => $imageType)); } } } $cal = new CDavICalendarComponent($arVCardContact); return $cal->Render(); }
function GetContentType($path, $bPhysicalName = false) { $io = CBXVirtualIo::GetInstance(); $pathX = $bPhysicalName ? $path : $io->GetPhysicalName($path); if (function_exists("mime_content_type")) { $type = mime_content_type($pathX); } else { $type = ""; } if (strlen($type) <= 0 && function_exists("image_type_to_mime_type")) { $arTmp = CFile::GetImageSize($pathX, true); $type = $arTmp["mime"]; } if (strlen($type) <= 0) { $arTypes = array("jpeg" => "image/jpeg", "jpe" => "image/jpeg", "jpg" => "image/jpeg", "png" => "image/png", "gif" => "image/gif", "bmp" => "image/bmp"); $type = $arTypes[strtolower(substr($pathX, bxstrrpos($pathX, ".") + 1))]; } return $type; }
protected static function resizePicture(&$f, $resize = array()) { $file = $f["tmp_name"]; $orig = file_exists($file) && is_file($file) ? \CFile::GetImageSize($file, true) : false; if ($orig) { $resize = is_array($resize) ? array_change_key_case($resize, CASE_LOWER) : array(); $resize = array("compression" => intval($resize["compression"]), "method" => $resize["method"] == "resample" ? "resample" : "resize", "width" => intval($resize["width"]), "height" => intval($resize["height"])); $size = array("width" => $orig[0], "height" => $orig[1]); $orientation = 0; $image_type = $orig[2]; if ($image_type == IMAGETYPE_JPEG) { $exifData = \CFile::extractImageExif($file); if ($exifData && isset($exifData['Orientation'])) { $orientation = $exifData['Orientation']; if ($orientation >= 5 && $orientation <= 8) { $size["width"] = $orig[1]; $size["height"] = $orig[0]; } } } $need = false; $source = array(); $destination = array(); \CFile::scaleImage($size["width"], $size["height"], $resize, BX_RESIZE_IMAGE_PROPORTIONAL, $need, $source, $destination); $image = false; if ($need || $orientation > 1) { if ($image_type == IMAGETYPE_JPEG) { $image = imagecreatefromjpeg($file); if ($image === false) { ini_set('gd.jpeg_ignore_warning', 1); $image = imagecreatefromjpeg($file); } if ($orientation > 1) { if ($orientation == 7 || $orientation == 8) { $image = imagerotate($image, 90, null); } elseif ($orientation == 3 || $orientation == 4) { $image = imagerotate($image, 180, null); } elseif ($orientation == 5 || $orientation == 6) { $image = imagerotate($image, 270, null); } if ($orientation == 2 || $orientation == 7 || $orientation == 4 || $orientation == 5) { \CFile::ImageFlipHorizontal($image); } } } elseif ($image_type == IMAGETYPE_GIF) { $image = imagecreatefromgif($file); } elseif ($image_type == IMAGETYPE_PNG) { $image = imagecreatefrompng($file); } } if ($image) { $image_p = imagecreatetruecolor($destination["width"], $destination["height"]); if ($image_type == IMAGETYPE_JPEG) { if ($resize["method"] === "resample") { imagecopyresampled($image_p, $image, 0, 0, 0, 0, $destination["width"], $destination["height"], $source["width"], $source["height"]); } else { imagecopyresized($image_p, $image, 0, 0, 0, 0, $destination["width"], $destination["height"], $source["width"], $source["height"]); } if ($resize["compression"] > 0) { imagejpeg($image_p, $file, $resize["compression"]); } else { imagejpeg($image_p, $file); } } elseif ($image_type == IMAGETYPE_GIF && function_exists("imagegif")) { imagetruecolortopalette($image_p, true, imagecolorstotal($image)); imagepalettecopy($image_p, $image); //Save transparency for GIFs $transparentColor = imagecolortransparent($image); if ($transparentColor >= 0 && $transparentColor < imagecolorstotal($image)) { $transparentColor = imagecolortransparent($image_p, $transparentColor); imagefilledrectangle($image_p, 0, 0, $destination["width"], $destination["height"], $transparentColor); } if ($resize["method"] === "resample") { imagecopyresampled($image_p, $image, 0, 0, 0, 0, $destination["width"], $destination["height"], $source["width"], $source["height"]); } else { imagecopyresized($image_p, $image, 0, 0, 0, 0, $destination["width"], $destination["height"], $source["width"], $source["height"]); } imagegif($image_p, $file); } else { //Save transparency for PNG $transparentColor = imagecolorallocatealpha($image_p, 0, 0, 0, 127); imagefilledrectangle($image_p, 0, 0, $destination["width"], $destination["height"], $transparentColor); $transparentColor = imagecolortransparent($image_p, $transparentColor); imagealphablending($image_p, false); if ($resize["method"] === "resample") { imagecopyresampled($image_p, $image, 0, 0, 0, 0, $destination["width"], $destination["height"], $source["width"], $source["height"]); } else { imagecopyresized($image_p, $image, 0, 0, 0, 0, $destination["width"], $destination["height"], $source["width"], $source["height"]); } imagesavealpha($image_p, true); imagepng($image_p, $file); } imagedestroy($image_p); imagedestroy($image); return true; } } return false; }
$fileId = intval($_REQUEST["i"]); $fileAction = $_REQUEST["act"] == "v" ? "view" : "download"; if (strlen($fileName) <= 0 || $fileId <= 0 || strlen($fileAction) <= 0) { die("Error1"); } $arImg = CFile::GetFileArray($fileId); if (!$arImg) { die("Error2"); } if (strlen($arImg["FILE_NAME"]) != strlen($fileName) || $arImg["FILE_NAME"] != $fileName) { die("Error3"); } if (strlen($arImg["SUBDIR"]) <= 0 || substr($arImg["SUBDIR"], 0, strlen("bizproc_wf/")) != "bizproc_wf/") { die("Error4"); } set_time_limit(0); if ($fileAction == "download") { CFile::ViewByUser($arImg, array("force_download" => true)); } else { $contentType = strtolower($arImg["CONTENT_TYPE"]); if (strpos($contentType, "image/") !== false && strpos($contentType, "html") === false && (CFile::GetImageSize($_SERVER["DOCUMENT_ROOT"] . $arImg["SRC"]) || $arFile["WIDTH"] > 0 && $arImg["HEIGHT"] > 0)) { $contentType = $contentType; } elseif (strpos($contentType, "excel") !== false) { $contentType = "application/vnd.ms-excel"; } elseif (strpos($contentType, "word") !== false) { $contentType = "application/msword"; } else { $contentType = "application/octet-stream"; } CFile::ViewByUser($arImg, array("content_type" => $contentType)); }
/** * @param $matches * @return string * @throws \Bitrix\Main\IO\FileNotFoundException */ protected function getReplacedImageCid($matches) { $src = $matches[3]; if ($src == "") { return $matches[0]; } if (array_key_exists($src, $this->filesReplacedFromBody)) { $uid = $this->filesReplacedFromBody[$src]["ID"]; return $matches[1] . $matches[2] . "cid:" . $uid . $matches[4] . $matches[5]; } $io = \CBXVirtualIo::GetInstance(); $filePath = $io->GetPhysicalName(\Bitrix\Main\Application::getDocumentRoot() . $src); if (!File::isFileExists($filePath)) { return $matches[0]; } foreach ($this->attachment as $attach) { if ($filePath == $attach['PATH']) { return $matches[1] . $matches[2] . "cid:" . $attach['ID'] . $matches[4] . $matches[5]; } } if ($this->settingMaxFileSize > 0) { $fileIoObject = new File($filePath); if ($fileIoObject->getSize() > $this->settingMaxFileSize) { return $matches[0]; } } $aImage = \CFile::GetImageSize($filePath, true); if (!is_array($aImage)) { return $matches[0]; } if (function_exists("image_type_to_mime_type")) { $contentType = image_type_to_mime_type($aImage[2]); } else { $contentType = $this->imageTypeToMimeType($aImage[2]); } $uid = uniqid(md5($src)); $this->filesReplacedFromBody[$src] = array("SRC" => $src, "PATH" => $filePath, "CONTENT_TYPE" => $contentType, "NAME" => bx_basename($src), "ID" => $uid); return $matches[1] . $matches[2] . "cid:" . $uid . $matches[4] . $matches[5]; }