Basically, I have this form data I'm trying to pass using cURL, here it is hardcoded into boundaries and just sending the request.
$postfields = '--Boundary+0xAbCdEfGbOuNdArY'."\r\n";
$postfields .= 'Content-Disposition: form-data; name="device_timestamp"'."\r\n\r\n";
$postfields .= (time() - (100 * rand(1,6)))."\r\n";
$postfields .= '--Boundary+0xAbCdEfGbOuNdArY'."\r\n";
$postfields .= 'Content-Disposition: form-data; name="photo"; filename="photo"'."\r\n";
$postfields .= 'Content-Type: image/jpeg'."\r\n\r\n";
$postfields .= file_get_contents($path)."\r\n";
$postfields .= '--Boundary+0xAbCdEfGbOuNdArY--'."\r\n";
$result = $this->curl_request('api.com/upload/',$postfields,array(
CURLOPT_HTTPHEADER => array(
'Content-type: multipart/form-data; boundary=Boundary+0xAbCdEfGbOuNdArY',
'Content-Length: '.strlen($postfields),
'Expect:'
)
));
How could I pass this data into a function like so?
private function multipart_build_query($fields){
$retval = '';
foreach($fields as $key => $value){
$retval .= "--".$this->boundary."\r\nContent-Disposition: form-data; name=\"$key\"\r\n\r\n$value\r\n";
}
$retval .= "--".$this->boundary."--";
return $retval;
}
I'm kind of guessing I'd have to modify my multipart_build_query
due to the following line : Content-Type: image/jpeg
I tried doing the following
$data_array = array(
"device_timestamp" => (time() - (100 * rand(1,6))),
"photo" => "@".$path,
);
$body = $curl->multipart_build_query($data_array);
yet to no avail