O
O
Obivankinobi2017-02-14 12:40:38
PHP
Obivankinobi, 2017-02-14 12:40:38

How to upload a picture to a profile via update??

Good afternoon, I ran into a problem when updating a user photo.
Actually the previous photo is deleted, but the new one does not appear. I rummaged through the Internet and did not find anything ((
There are no errors, at the end the script returns true ..

$arFile2 = CFile::MakeFileArray($_FILES['file']['tmp_name'][0]);
$userId =  $USER->GetId();
$rsUser = CUser::GetByID($userId);
$arUser = $rsUser->Fetch();
$arFile2['del'] = "Y";           
$arFile2['old_file'] = $arUser["PERSONAL_PHOTO"];
$arFile2["MODULE_ID"] = "main";

$fid = CFile::SaveFile($arFile2, "main");

$fields = Array( "PERSONAL_PHOTO" => $fid );

$user = new CUser;
$res = $user->Update($userId, $fields);
$strError .= $user->LAST_ERROR;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita, 2017-02-14
@Obivankinobi

$arr_file = array(
  "name" =>$_FILES['file']['name'],
  "size" =>$_FILES['file']['size'],
  "tmp_name" =>$_FILES['file']['tmp_name'],
  "type" => "",
  "old_file" => "",
  "del" => "Y",
  "MODULE_ID" => ""
);

$fid = CFile::SaveFile($arr_file, "patch");

And you don't need to use CFile::MakeFileArray. This function generates an analogue of the one you have in $_FILES
And if you pass the image through FormData () then you have an inverted array in $_FILES, it needs to be processed. Look here
And also try in$fields = Array( "PERSONAL_PHOTO" => $arFile2 );

O
Oleg Maksimenko, 2017-02-14
@olegprof

Show the contents of the $arFile2 array when the file is loaded

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question