- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/file.php
- Класс: CFile
- Вызов: CFile::CheckFile
static function CheckFile($arFile, $intMaxSize=0, $mimeType=false, $strExt=false, $bForceMD5=false, $bSkipExt=false)
{
if($arFile["name"] == "")
{
return "";
}
//translit, replace unsafe chars, etc.
$strFileName = self::transformName($arFile["name"], $bForceMD5, $bSkipExt);
//transformed name must be valid, check disk quota, etc.
if(($error = self::validateFile($strFileName, $arFile)) <> '')
{
return $error;
}
if($intMaxSize > 0 && $arFile["size"] > $intMaxSize)
{
return GetMessage("FILE_BAD_SIZE")." (".static::FormatSize($intMaxSize).").";
}
$strFileExt = '';
if($strExt)
{
$strFileExt = GetFileExtension($strFileName);
if($strFileExt == '')
{
return GetMessage("FILE_BAD_TYPE");
}
}
//Check mime type
if($mimeType !== false)
{
if(!is_array($mimeType))
{
$mimeType = array($mimeType);
}
$goodMime = false;
foreach($mimeType as $strMimeType)
{
if(substr($arFile["type"], 0, strlen($strMimeType)) == $strMimeType)
{
$goodMime = true;
break;
}
}
if(!$goodMime)
{
return GetMessage("FILE_BAD_TYPE");
}
}
//Check extension
if($strExt === false)
{
return "";
}
$IsExtCorrect = true;
if($strExt)
{
$IsExtCorrect = false;
$tok = strtok($strExt,",");
while($tok)
{
if(strtolower(trim($tok)) == strtolower($strFileExt))
{
$IsExtCorrect = true;
break;
}
$tok = strtok(",");
}
}
if($IsExtCorrect)
{
return "";
}
return GetMessage("FILE_BAD_TYPE")." (".strip_tags($strFileExt).")";
}