• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/file.php
  • Класс: CFile
  • Вызов: CFile::MakeFileArray
static function MakeFileArray($path, $mimetype = false, $skipInternal = false, $external_id = "")
{
	$io = CBXVirtualIo::GetInstance();
	$arFile = array();

	if(intval($path)>0)
	{
		if ($skipInternal)
			return false;

		$res = static::GetByID($path);
		if($ar = $res->Fetch())
		{
			$bExternalStorage = false;
			foreach(GetModuleEvents("main", "OnMakeFileArray", true) as $arEvent)
			{
				if(ExecuteModuleEventEx($arEvent, array($ar, &$arFile)))
				{
					$bExternalStorage = true;
					break;
				}
			}

			if(!$bExternalStorage)
			{
				$arFile["name"] = ($ar['ORIGINAL_NAME'] <> ''?$ar['ORIGINAL_NAME']:$ar['FILE_NAME']);
				$arFile["size"] = $ar['FILE_SIZE'];
				$arFile["type"] = $ar['CONTENT_TYPE'];
				$arFile["description"] = $ar['DESCRIPTION'];
				$arFile["tmp_name"] = $io->GetPhysicalName(preg_replace("#[\\\/]+#", "/", $_SERVER['DOCUMENT_ROOT'].'/'.(COption::GetOptionString('main', 'upload_dir', 'upload')).'/'.$ar['SUBDIR'].'/'.$ar['FILE_NAME']));
			}
			if (!isset($arFile["external_id"]))
			{
				$arFile["external_id"] = $external_id != ""? $external_id: $ar["EXTERNAL_ID"];
			}
			return $arFile;
		}
	}

	$path = preg_replace("#(?setPrivateIp(false);
			$temp_path = static::GetTempName('', 'tmp.'.md5(mt_rand()));
			if($http->download($path, $temp_path))
			{
				$arFile = static::MakeFileArray($temp_path);
				if($arFile)
				{
					$urlComponents = parse_url($path);
					if($urlComponents && $urlComponents["path"] <> '')
					{
						$arFile["name"] = $io->GetLogicalName(bx_basename($urlComponents["path"]));
					}
					else
					{
						$arFile["name"] = $io->GetLogicalName(bx_basename($path));
					}
				}
			}
		}
		elseif($temp_path)
		{
			$arFile = static::MakeFileArray($temp_path);
		}
	}
	elseif(preg_match("#^(ftp[s]?://|php://input)#i", $path))
	{
		if($fp = fopen($path,"rb"))
		{
			$content = "";
			while(!feof($fp))
			{
				$content .= fgets($fp, 4096);
			}

			if($content <> '')
			{
				$temp_path = static::GetTempName('', 'tmp.'.md5(mt_rand()));
				if(RewriteFile($temp_path, $content))
				{
					$arFile = static::MakeFileArray($temp_path);
					if($arFile)
					{
						$arFile["name"] = $io->GetLogicalName(bx_basename($path));
					}
				}
			}

			fclose($fp);
		}
	}
	else
	{
		if(!file_exists($path))
		{
			if (file_exists($_SERVER["DOCUMENT_ROOT"].$path))
				$path = $_SERVER["DOCUMENT_ROOT"].$path;
			else
				return null;
		}

		if(is_dir($path))
			return null;

		$arFile["name"] = $io->GetLogicalName(bx_basename($path));
		$arFile["size"] = filesize($path);
		$arFile["tmp_name"] = $path;
		$arFile["type"] = $mimetype;

		if($arFile["type"] == '')
			$arFile["type"] = static::GetContentType($path, true);
	}

	if($arFile["type"] == '')
		$arFile["type"] = "unknown";

	if (!isset($arFile["external_id"]) && ($external_id != ""))
	{
		$arFile["external_id"] = $external_id;
	}

	return $arFile;
}