| Цитата |
|---|
Андрей Николаев написал: Дмитрий Краев , уже проще использовать main.file.input - он сразу ID файла закидывает |
с вашим подходом, вам лучше использовать инфоблоки и только как пользователь.
по факту деладобавление папки /upload/tmp не совсем правильно решение
правильную обработку приведу из файла /bitrix/modules/sender/admin/mailing_chain_edit.php
| Код |
|---|
//Brandnew
$arFiles = array();
if(is_array($_FILES["NEW_FILE"]))
{
foreach($_FILES["NEW_FILE"] as $attribute=>$files)
{
if(is_array($files))
foreach($files as $index=>$value)
$arFiles[$index][$attribute]=$value;
}
foreach($arFiles as $index => $file)
{
if(!is_uploaded_file($file["tmp_name"]))
unset($arFiles[$index]);
}
}
//New from media library and file structure
if(array_key_exists("NEW_FILE", $_POST) && is_array($_POST["NEW_FILE"]))
{
foreach($_POST["NEW_FILE"] as $index=>$value)
{
if (is_string($value) && preg_match("/^https?:\\/\\//", $value))
{
$arFiles[$index] = CFile::MakeFileArray($value);
}
else
{
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'];
}
}
}
}
}
foreach($arFiles as $file)
{
if(strlen($file["name"])>0 and intval($file["size"])>0)
{
$resultInsertAttachFile = false;
$file["MODULE_ID"] = "main";
$fid = intval(CFile::SaveFile($file, "sender", true));
if($fid > 0)
{
$resultAddAttachFile = \Bitrix\Sender\MailingAttachmentTable::add(array(
'CHAIN_ID' => $ID,
'FILE_ID' => $fid
));
$resultInsertAttachFile = $resultAddAttachFile->isSuccess();
}
if(!$resultInsertAttachFile)
break;
}
}
|