Reply
Regular Visitor
acomer
Posts: 2
0
Accepted Solution

Case attachments populating from php code, but files truncated at 8kb

I am trying to attach files to Salesforce cases via php. The file information is coming across okay and the attachment is getting created, but the files themselves are getting truncated at 8kb. Also, this is development work that's pointing to a Salesforce sandbox instance. Code snippet is as follows:

 

$mySforceConnection = $sf->client;

$sAttachment= new stdClass;

$handle = fopen($filepath,'r+');
$file_content = fread($handle,filesize($filepath));
fclose($handle);
$encoded = chunk_split(base64_encode($file_content));

$sAttachment->Body = $encoded;
$sAttachment->Name = $filename;
$sAttachment->ParentId = $sf_caseid;

$response = $mySforceConnection->create(array($sAttachment),'Attachment');

Regular Visitor
acomer
Posts: 2
0

Re: Case attachments populating from php code, but files truncated at 8kb

Resolved this.

 

Using "stream_get_contents($handle)" instead of "fread($handle,filesize($filepath))" did the trick.

 

Reference: http://php.net/manual/en/function.fread.php