如何将多个文件从文件夹上传到Dropbox文件夹

时间:2017-03-03 08:56:54

标签: curl dropbox-api

我有一个文件夹,在该文件夹中有4个文件,我想将此文件夹中的所有文件上传到dropbox文件夹。

我该怎么做。?

以下是我的代码:

     $ch = curl_init();
     $TOKEN = "token";
     $url = 'https://content.dropboxapi.com/2/files/upload';
     $cron_log = site_url().'/foldername';

     $fp = fopen($cron_log, 'rb');
     $size=filesize($cron_log);

     curl_setopt($ch,CURLOPT_URL,$url);
     curl_setopt($ch,CURLOPT_POST, 1);              
     curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
     $headers = array();
     $headers[] = 'Content-Type:application/octet-stream';
     $headers[] = 'Dropbox-API-Arg:{"path":"/home/test/address_proof.pdf","mode":{".tag":"add"},"autorename":false,"mute":false}';
     $headers[] = "Authorization: Bearer ".$TOKEN;
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);  
     //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);  
     $droplist  = json_decode($response,true);

1 个答案:

答案 0 :(得分:0)

/ 2 / files / upload Dropbox API端点允许您每次调用上传一个文件。如果您需要上传多个文件,则需要多次调用它。在您的情况下,您需要调用它4次才能上传4个文件。确保为每个值指定相关的{ "targets": [ { "target_name": "addon", "sources": [ "main.cpp" ], 'xcode_settings': { 'OTHER_CFLAGS': [ "-std=c++11", "-stdlib=libc++" ], } } ] } 值。例如,您可以在此处指定要上载文件的路径。