dsu5188 2015-12-10 10:59
浏览 30

Dropbox PHP v2上传问题

I did a php cURL code, the result is success but the problem it return the size 0, can anyone help me out, I do use the code on this page Dropbox v2 API - large file uploads I'm not sure why the file size is zero. can anyone help me out?

Also this is the return from the request 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}

Thanks,

UPDATE (CODE):

$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);
  • 写回答

1条回答 默认 最新

  • drjyvoi734793 2015-12-10 22:37
    关注

    This version of the code seems to trick curl into acting like it's a PUT request, but has it send "POST" as necessary.

    <?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);
    
    ?>
    

    That yields:

    {"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}
    
    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条