1

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

1

This got worked by removing the CURLOPT_HEADER option.

 curl_setopt($ch, CURLOPT_HEADER, 1); //remove
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.