Dropbox PHP v2上传问题


Dropbox PHP v2 upload issue

我做了一个php cURL代码,结果是成功的,但问题是它返回大小为0,有人能帮我吗?我确实使用了这个页面上的代码Dropbox v2 API-大文件上传我不知道为什么文件大小为零。有人能帮我吗?

这也是请求cURL 的返回

{"name": "2.jpg", "path_lower": "/images/2.jpg", "id": "id:92FZUH08Y6AAAAAVVAAAEA", "client_modified": "2015-12-10T11:02:38Z", "server_modified": "2015-12-10T11:02:38Z", "rev": "1c40f677f1", "size": 0}

谢谢,

更新(代码):

$filename='2.jpg';
$cheaders = array('Authorization: Bearer =TOKEN=','Content-Type: application/octet-stream','Dropbox-API-Arg: {"path":"/images/'.$filename.'", "mode":"add"}');
$ch = curl_init('https://content.dropboxapi.com/2/files/upload');
curl_setopt($ch, CURLOPT_HTTPHEADER, $cheaders );
curl_setopt($ch, CURLOPT_POST, true);
$fpath = '/home2/public_html/uploads/'.$filename;
$fp = fopen($fpath, 'rb');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($fpath));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
fclose($fp);

这个版本的代码似乎欺骗了curl,使其表现得像一个PUT请求,但让它在必要时发送"POST"。

<?php
$path = 'test_php_upload.txt';
$fp = fopen($path, 'rb');
$size = filesize($path);
$cheaders = array('Authorization: Bearer =TOKEN=',
                  'Content-Type: application/octet-stream',
                  'Dropbox-API-Arg: {"path":"/test/'.$path.'", "mode":"add"}');
$ch = curl_init('https://content.dropboxapi.com/2/files/upload');
curl_setopt($ch, CURLOPT_HTTPHEADER, $cheaders);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, $size);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo $response;
curl_close($ch);
fclose($fp);
?>

这就产生了:

{"name": "test_php_upload.txt", "path_lower": "/test/test_php_upload.txt", "id": "id:25N5ksooX-sAAAAAAAHcWg", "client_modified": "2015-12-10T22:35:07Z", "server_modified": "2015-12-10T22:35:07Z", "rev": "56384021eccc7", "size": 15}