You're very close - the tricky bit is that the Chatter REST API is expecting a multipart form. Also, it wants the message segments as its own array. After some poking around it looks like the easiest way to handle it is by wrangling the post data together.
I'm using this doc as a base: http://www.salesforce.com/us/developer/docs/chatterapi/Content/intro_input.htm
And here is my script, note that I pasted the url manually (which you should not):
<?php
$url = "https://na15.salesforce.com/services/data/v29.0/chatter/feeds/record/500i0000004AcIq/feed-items";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
$fileName = basename($file);
$headers = array();
$headers[] = "Authorization: OAuth {token}";
$headers[] = 'Content-Type: multipart/form-data; boundary=F9jBDELnfBLAVmLNbnLIYibT5Icp0h3VJ7mkI';
$segments = array();
$segments['type'] = 'Text';
$segments['text'] = 'User uploaded attachment';
$message = array();
$message[] = $segments;
$dataArray = array(
'body' => array(
'messageSegments' => $message
),
'attachment' => array(
'attachmentType' => 'NewFile',
'title' => 'Test File'
)
);
$data = $data.json_encode($dataArray);
$file = realpath('phoenix-logo.png');
$post_text = '--F9jBDELnfBLAVmLNbnLIYibT5Icp0h3VJ7mkI
Content-Disposition: form-data; name="json"
Content-Type: application/json; charset=UTF-8
{ "body":
{
"messageSegments" : [
{
"type" : "Text",
"text" : "Here is another file for review."
}, {
"type" : "Hashtag",
"tag" : "important"
}, {
"type" : "Text",
"text" : "Again, please review this as soon as possible."
}
]
},
"attachment":
{
"attachmentType" : "NewFile",
"description": "Phoenix Logo",
"title" : "Logo.png"
}
}
--F9jBDELnfBLAVmLNbnLIYibT5Icp0h3VJ7mkI
Content-Disposition: form-data; name="feedItemFileUpload"; filename="logo.png"
Content-Type: image/png
'.file_get_contents($file).'
--F9jBDELnfBLAVmLNbnLIYibT5Icp0h3VJ7mkI--';
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_text);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
$response_json = curl_exec($curl);
print $response_json;
?>
Best Answer
With Summer '14 release, file size limits for attachments were increased to 25MB, so you should be fine:
http://docs.releasenotes.salesforce.com/en-gb/summer14/release-notes/rn_general_attachment_size_increase.htm