Y
Y
Yuriy2019-07-25 09:34:41
1C-Bitrix
Yuriy, 2019-07-25 09:34:41

Bitrix CEvent::Send &CFile::MakeFileArray Are there 2 identical files in the message?

Hello everyone, the question is, why are there 2 identical attachments in the letter?

$file = CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"]."/temp/".$MGR_ID.'_'.date("dmYHi").'.xlsx');

     $arEventField = array(  
          "EMAIL_TO" => $USER->GetEmail(),
          "USER_NAME" => $USER->GetFullName(),
          "FILE" => $file
        );
        //var_dump($file);

        if(CEvent::Send("MGR_INFORMER", 's1', $arEventField,'Y','',$file)){  // array($file) если указать файл в массиве, то вообще файл не прикрепляется...
        	@unlink($_SERVER["DOCUMENT_ROOT"]."/temp/".$MGR_ID.'_'.date("dmYHi").'.xlsx');
        }

to $file array from
array(4) {
  ["name"]=>
  string(19) "1_250720190933.xlsx"
  ["size"]=>
  int(32177)
  ["tmp_name"]=>
  string(70) "/var/www/vhosts/site.ru/httpdocs/temp/1_250720190933.xlsx"
  ["type"]=>
  string(65) "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Nikolaev, 2019-07-25
@yous

1) You do not need to specify the FILE key in $arEventField, it will itself be set from the 6th parameter of the CEvent::Send method
2) \CFile::MakeFileArray does not need to be done at all. On the last Bitrix, they do it for you.
Those. in your case the code should look something like this:

$fileName = $_SERVER["DOCUMENT_ROOT"]."/temp/".$MGR_ID.'_'.date("dmYHi").'.xlsx';

$files = [
  $fileName
];

$arEventField = [
  "EMAIL_TO"  => $USER->GetEmail(),
  "USER_NAME" => $USER->GetFullName(),
];

if ( \CEvent::Send("MGR_INFORMER", "s1", $arEventField, "Y", '', $files ) )
{
  @unlink($fileName);
}

If, after the done files, 2 is still attached, then it is necessary:
​​1) Check the MGR_INFORMER template; perhaps the file insertion is registered in the template itself. If the file is inserted into the body of the letter, then it can be duplicated 2 times.
2) Check the OnBeforeEventAdd events of the main module. Perhaps there is a duplicate file.
3) Check the custom_mail function (if it exists). Perhaps additional work with files is located there.

Y
Yuriy, 2019-07-25
@yous

the issue was resolved like this $file['tmp_name'] ...

if(CEvent::Send("MGR_INFORMER", 's1', $arEventField,'Y','',[$file['tmp_name']])){

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question