I'm trying to upload a file using curl and php with the following code. I'm passing post data as a string using http_build_query rather than an array because post data is a multi part array. Code works except I can't get image to upload.
$ch = curl_init();
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIE, $cookie1);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$image=file_get_contents(realpath('image.jpg'));
$postFields = array(
'authenticity_token'=>$token1.'=',
'menu_item'=>array('name' => $name,
'body'=>'',
'published'=>0,
'published'=>1,
'picture'=>$image,
);
$postData=http_build_query($postFields);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_exec ($ch);