I'm using the below php code to save the Attachment to my server.

 public function getAttachmentFileFromSalesForce($fileName, $fileBodyUrl)
        try {
            $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);
            return true;

        } catch (Exception $e) {
        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

1 Answer 1


This got worked by removing the CURLOPT_HEADER option.

 curl_setopt($ch, CURLOPT_HEADER, 1); //remove

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .