I'm trying to upload a file on a form on my site, and then pass it on to a remote API.
This is my PHP:
$fields = array(
'file'=>$_FILES["mediaupload"],
'username'=>urlencode($_POST["username"]),
'password'=>urlencode($_POST["password"]),
'latitude'=>urlencode($_POST["latitude"]),
'longitude'=>urlencode($_POST["longitude"]),
);
$fields_string = http_build_query($fields);
$url = my_url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec ($ch);
At the moment I keep getting error messages that the file could not be processed properly. The API expects all fields as POST strings except the file, which it expects in binary.
I know it's going to be tough to debug this for you guys without access to the remote API, but am I doing anything obviously wrong, or should this work?
Many thanks.