# Upload user picture with API and PHP

**URL:** <https://devforum.zoom.us/t/upload-user-picture-with-api-and-php/13515>\
**Category:** API and Webhooks\
**Created:** [April 16, 2020, 2:48pm UTC](https://devforum.zoom.us/t/upload-user-picture-with-api-and-php/13515 "2020-04-16T14:48:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lelkamel](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/lelkamel/32/6435_2.png) [@lelkamel](https://devforum.zoom.us/u/lelkamel)\
**Post date:** [April 16, 2020, 2:48pm UTC](https://devforum.zoom.us/t/upload-user-picture-with-api-and-php/13515/1 "2020-04-16T14:48:09Z")

</div>

Hello everyone,

I m trying to upload profile picture for a specific user with file\_get\_contents() and i have also tried with CURL.

I tried everything and i keep getting error 400.

There’s my code:

$token = “xxxxxxxxxxxxxxxxxxxxxxxxxxx”;  
$userid = ‘xxxxxxxxxxxxx’;  
$picpath = file\_get\_contents(“G:/wamp/www/images/awesompicture.png”);  
$token = urlencode($token);  
$api\_url = ‘[https://api.zoom.us/v2/](https://api.zoom.us/v2/)’;  
$ressource = ‘users/’ . $userid . ‘/picture’;  
$request\_url = $api\_url . $ressource;

define(‘MULTIPART\_BOUNDARY’, ‘--------------------------’ . microtime(true));  
$header = ‘Content-Type: multipart/form-data; boundary=’ . MULTIPART\_BOUNDARY;  
$data = array(  
“pic\_file” =\> $picpath  
);  
$tableau = json\_encode($data);  
$context = stream\_context\_create(array(  
‘http’ =\> array(  
‘method’ =\> ‘POST’,  
‘header’ =\> 'Authorization: Bearer ’ . “$token”,  
$header,  
‘content’ =\> $data  
)  
));  
file\_get\_contents($request\_url, false, $context);

Do you guys know what i’m missing? Thanks in advance.

Have a great day

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [April 17, 2020, 6:29pm UTC](https://devforum.zoom.us/t/upload-user-picture-with-api-and-php/13515/2 "2020-04-17T18:29:57Z")

</div>

Hey @lelkamel,

Is there an error message returned with the 400 error?

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![lelkamel](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/lelkamel/32/6435_2.png) [@lelkamel](https://devforum.zoom.us/u/lelkamel)\
**Post date:** [April 18, 2020, 12:27pm UTC](https://devforum.zoom.us/t/upload-user-picture-with-api-and-php/13515/3 "2020-04-18T12:27:02Z")

</div>

Hello Tommy,

I solved this issue with Curl.  
the PHP Code generated by the API doesnt work.  
There’s my woking version:

function postavatar($token, $userid, $image, $imagename){  
$fields = [  
‘pic\_file’ =\> new \CurlFile($image, ‘image/png’, $imagename)  
];  
$curl = curl\_init();  
curl\_setopt\_array($curl, array(  
CURLOPT\_URL =\> “[https://api.zoom.us/v2/users/$userid/picture](https://api.zoom.us/v2/users/%24userid/picture)”,  
CURLOPT\_RETURNTRANSFER =\> true,  
CURLOPT\_ENCODING =\> “”,  
CURLOPT\_MAXREDIRS =\> 10,  
CURLOPT\_TIMEOUT =\> 30,  
CURLOPT\_SSL\_VERIFYPEER =\> FALSE,  
CURLOPT\_HTTP\_VERSION =\> CURL\_HTTP\_VERSION\_1\_1,  
CURLOPT\_CUSTOMREQUEST =\> “POST”,  
CURLOPT\_POSTFIELDS =\> $fields ,  
CURLOPT\_HTTPHEADER =\> array(  
“authorization: Bearer $token”,  
“content-type: multipart/form-data”  
),  
));

```
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
  return "NONE";
} else {
  return $response;
}

```

}

I hope it will help people whot got the same issue

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [April 20, 2020, 8:55pm UTC](https://devforum.zoom.us/t/upload-user-picture-with-api-and-php/13515/4 "2020-04-20T20:55:21Z")

</div>

Hey @lelkamel, happy to hear you got it working! 🙂

Thanks for posting the solution too!

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![DeveloperBot](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/developerbot/32/12632_2.png) [@DeveloperBot](https://devforum.zoom.us/u/DeveloperBot)\
**Post date:** [August 21, 2020, 8:32pm UTC](https://devforum.zoom.us/t/upload-user-picture-with-api-and-php/13515/5 "2020-08-21T20:32:33Z")

</div>

Closed on August 21, 2020, 8:32pm UTC


