Skip to content

Instantly share code, notes, and snippets.

@konratnox
Created February 1, 2019 09:16
Show Gist options
  • Save konratnox/c5484c6c7152fb3d21a0a284eceba0a8 to your computer and use it in GitHub Desktop.
Save konratnox/c5484c6c7152fb3d21a0a284eceba0a8 to your computer and use it in GitHub Desktop.
<?
foreach ($_POST['NEW_PHOTO_SIZE'] as $index=>$value) {
if(is_array($value))
{
$filePath = $value['tmp_name'];
}
else
{
$filePath = $value;
}
// проверяется временный путь, получаем временную папку, сравниваем, если неправильный путь -
$isCheckedSuccess = false;
$io = CBXVirtualIo::GetInstance();
$docRoot = \Bitrix\Main\Application::getDocumentRoot();
if(strpos($filePath, CTempFile::GetAbsoluteRoot()) === 0)
{
$absPath = $filePath;
}
elseif(strpos($io->CombinePath($docRoot, $filePath), CTempFile::GetAbsoluteRoot()) === 0)
{
$absPath = $io->CombinePath($docRoot, $filePath);
}
else
{
$absPath = $io->CombinePath(CTempFile::GetAbsoluteRoot(), $filePath);
}
if ($io->ValidatePathString($absPath) && $io->FileExists($absPath))
{
$docRoot = $io->CombinePath($docRoot, '/');
$relPath = str_replace($docRoot, '', $absPath);
$perm = $APPLICATION->GetFileAccessPermission($relPath);
if ($perm >= "W")
{
$isCheckedSuccess = true;
}
}
if($isCheckedSuccess)
{
$arFiles[$index] = CFile::MakeFileArray($io->GetPhysicalName($absPath));
if(is_array($value))
{
$arFiles[$index]['name'] = $value['name'];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment