我在salesforce中有一个函数,我可以在其中获得可以是任何文件类型的附件(pdf,xls,png,...)。
function getData($access_token,$instance_url,$url){
$url = $instance_url."/services/data/v32.0/".$url;
$headers = array('Authorization: OAuth ' . $access_token);
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
//curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, TRUE );
//curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers);
$requestBody = curl_exec ($ch);
$result = json_decode($requestBody, true);
return $result;
}
$attId = "00P0f00000ly5ZCEAY";
$body = "sobjects/Attachment/00P0f00000ly5ZCEAY/Body";
$file = getData($access_token,$instance_url,$body);
结果是文件以二进制形式返回。
所以$ file = //一些二进制文件
如何使用$ file在本地保存?
现在这个函数的结果是:
??%???T?)???)?eFa???Bɶ?l6???,?0?l?%kc?w?cՂX8?"?*Q>?ē??/y???=??T??Ċ?sǓ???l...
.
...
似乎是在尝试将文件打印到我的屏幕上。
答案 0 :(得分:0)
需要设置正确的curl_opts
$headers = array('Authorization: OAuth ' . $access_token);
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt ( $ch, CURLOPT_BINARYTRANSFER, TRUE );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers);