I'm using the below php code
to save the Attachment to my server.
public function getAttachmentFileFromSalesForce($fileName, $fileBodyUrl)
{
try {
$authCode='';
$instanceUrl = '';
$filePath = storage_path('sf_files') . '/' . $fileName;
$headers= array('Authorization: Bearer ' . $authCode);
$ch = curl_init($instanceUrl . $fileBodyUrl);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
$tempFP = fopen($filePath, 'w+');
curl_setopt($ch, CURLOPT_FILE, $tempFP);
curl_exec($ch);
curl_close($ch);
fclose($tempFP);
return true;
} catch (Exception $e) {
//silence
}
return false;
}
This is working fine for pdf files. But in the case of xlsm, the file shows some junk data like below.
戮J9�ε�����o��/��N�o���L�Z�:%m���S�/k ����)�3iG�E$v��Ď7��q�o#��4