我尝试使用CURL PHP更新REST API中的个人资料照片,但似乎无效,它返回null而不是成功的消息。 这是我的代码:
<form action="index.php" method="post" enctype="multipart/form-data" />
<input type="file" name="image" />
<input type="submit" value="Post" />
</form>
<?php
if(isset($_FILES['image']['tmp_name'])){
$curl = curl_init();
$cfile=new CURLFile($_FILES['image']['tmp_name'],$_FILES['image']['type'],$_FILES['image']['name']);
$data=http_build_query(array("myimage"=>$cfile));
curl_setopt_array($curl, array(
CURLOPT_URL => "http://xxxxx.ph/socialengine/socialapi/member/post/profilePhoto?apiKey=12345678&secretKey=12345679&version=1.0&userId=1",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_SAFE_UPLOAD=> false,
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: multipart/form-data; boundary=---011000010111000001101001",
"postman-token: 1f21a6a9-8b25-0f68-0231-72466dede66a"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
}
?>