и оправляется
смотрите массивы с файлом же уходят, что не так с кодом?
array(4) { ["TITLE"]=>
string(17) "работает5"
["ASSIGNED_BY_ID"]=>
int(1)
["UF_CRM_2_1699357410466"]=>
array(4) {
["name"]=>
string(40) "dbe4cf0833e30a295e5434a613606e31 (1).jpg"
["size"]=>
int(78229)
["tmp_name"]=>
string(74) "/home/bitrix/www/upload/from_mail/dbe4cf0833e30a295e5434a613606e31 (1).jpg"
["type"]=>
string(10) "image/jpeg"
}
["STAGE_ID"]=>
string(11) "DT182_4:NEW"
}
array(4) {
["TITLE"]=>
string(17) "работает5"
["ASSIGNED_BY_ID"]=>
int(1)
["UF_CRM_2_1699357410466"]=>
array(6) {
["name"]=>
string(32) "4b58ed95fefc71ca92feebe89b46ead0"
["size"]=>
string(4) "1257"
["type"]=>
string(10) "text/plain"
["description"]=>
string(0) ""
["tmp_name"]=>
string(109) "/home/bitrix/www/upload/mail/attachment/8b5/l1feemmmm0jgo01vhympfc478yepn7ki/4b58ed95fefc71ca92feebe89b46ead0"
["external_id"]=>
string(32) "9855cf44286fc6cf32a68108d07abb2d"
}
["STAGE_ID"]=>
string(11) "DT182_4:NEW"
}
<?php
use Bitrix\Main\Diag\Debug;
use Bitrix\Crm\Service;
use Bitrix\Main\Loader;
use Bitrix\Crm\Item;
CModule::IncludeModule('mail');
CModule::IncludeModule('crm');
CModule::IncludeModule('tasks');
$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler('mail', 'onMailMessageNew', 'onMailMessageNew');
function onMailMessageNew($event)
{
$message = $event->getParameter('message');
$dbr_attach = CMailAttachment::GetList(Array("NAME" => "ASC", "ID" => "ASC"), Array("MESSAGE_ID" => $message['ID']));
while ($dbr_attach_arr = $dbr_attach->GetNext()) {
if ($dbr_attach_arr["FILE_NAME"]=='1.tmp' ||
preg_match_all('/\\.(?:exe|html|phtml|pl|js|htm|py|php|php4|php3|phtml|shtml)$/i', $dbr_attach_arr["FILE_NAME"], $p_matches, PREG_PATTERN_ORDER))
continue;
$attach_id = $dbr_attach_arr["ID"];
$dbr = CMailAttachment::GetByID($attach_id);
if($dbr_arr = $dbr->Fetch())
{
$fname = $_SERVER['DOCUMENT_ROOT']."/upload/from_mail/".$dbr_attach_arr["FILE_NAME"];
$handle = fopen($fname, 'wb');
fwrite($handle, $dbr_arr["FILE_DATA"]);
fclose($handle);
$arFile = CFile::MakeFileArray($fname);
//нерабочий код
$storage = Bitrix\Disk\Driver::getInstance()->getStorageByUserId(1);
$folder = $storage->getFolderForUploadedFiles();
$file = $folder->uploadFile($arFile, array(
'NAME' => $arFile["name"],
'CREATED_BY' => 1
), array(), true);
$FILE_ID = $file->getId();
//нерабочий код
$typeid = '182';//Идентификатор смарт-процесса
$userId = 1;
$factory = Service\Container::getInstance()->getFactory($typeid);
//Ниже рабочий
$data = [
'TITLE' => 'работает5',
'ASSIGNED_BY_ID'=>$userId,
'UF_CRM_2_1699357410466'=>CFile::MakeFileArray($FILE_ID),
'STAGE_ID' => 'DT182_4:NEW',
];
$item = $factory ->createItem($data);
$item->save();
Debug::dumpToFile($data);
}
}
}
```
выше же писал, как прикреплять
Обсуждают сегодня