I need to upload a simple string via api - there is no "file" on the server - the string will be generated in my PHP code. First, does it need to be in binary? Second, when I upload, I get a "1" written into a file - and thats it. How do I get that string uploaded? I don't get any errors back. Help!
$fields = array(
"path" => "/ba.txt",
"autorename" => false,
"mode" => "overwrite",
"mute" => false,
"strict_conflict" => false );
$string = 'hello there';
$binary = strigToBinary($string).PHP_EOL;
$headers = array(
'Authorization: Bearer ' . $auth_token,
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: '.json_encode($fields)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, 'https://content.dropboxapi.com/2/files/upload');
curl_setopt($ch, CURLOPT_INFILE, $binary);
and here is my binary function
function strigToBinary($string) {
$characters = str_split($string);
$binary = [];
foreach ($characters as $character) {
$data = unpack('H*', $character);
$binary[] = base_convert($data[1], 16, 2);
}
return implode(' ', $binary);
}