I am working with an API that is asking me to do a http post to their server which has a tab-delimited batch file in the message-body. I am currently using curl to handle the HTTP Post but I am not sure how I would add a file to the message body? Anyone able to help?
Like this: function execURL($url, $data = NULL){ $postlen = count($data); foreach($data as $key=>$value) { $fields .= $key.'='.$value.'&'; } rtrim($fields,'&'); $ch = curl_init(); $timeout = 10; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); curl_setopt($ch,CURLOPT_POST,$postlen); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields); $response = curl_exec($ch); curl_close($ch); return $response; } PHP: $data being thearray of data you want to post. If you have 3 variables lets say - id, status and msg It should be - $data = array('id'=>$id, 'status'=>$status, 'msg'=>$msg);
This usergroup email about posting files using curl might be helpful too http://groups.google.com/group/nzph...ba0/2a38883726052a79?lnk=gst#2a38883726052a79