【问题标题】:PHP Form : Upload File using Dropbox version 2 ApiPHP 表单:使用 Dropbox 版本 2 Api 上传文件
【发布时间】:2018-06-01 17:03:40
【问题描述】:

请推荐一个使用Dropbox版本2的php表单文件上传代码。

【问题讨论】:

    标签: dropbox dropbox-api dropbox-php


    【解决方案1】:

    从 Dropbox 应用获取访问令牌后,运行以下代码,您的文件将上传到 Dropbox

     <?php
    $filename = 'pr.jpg';
    
    $api_url = 'https://content.dropboxapi.com/2/files/upload'; //dropbox api url
            $token = 'Generated access token'; // oauth token
    
            $headers = array('Authorization: Bearer '. $token,
                'Content-Type: application/octet-stream',
                'Dropbox-API-Arg: '.
                json_encode(
                    array(
                        "path"=> '/'. basename($filename),
                        "mode" => "add",
                        "autorename" => true,
                        "mute" => false
                    )
                )
    
            );
    
            $ch = curl_init($api_url);
    
           curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
           curl_setopt($ch, CURLOPT_POST, true);
    
            $path = $filename;
    
    
            $fp = fopen($path, 'rb');
            $filesize = filesize($path);
    
             curl_setopt($ch, CURLOPT_POSTFIELDS, fread($fp, $filesize));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_VERBOSE, 1); // debug
    
            $response = curl_exec($ch);
    
    
            $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    
    
    
            echo($response.'<br/>');
            echo($http_code.'<br/>');
    
            curl_close($ch);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-23
      • 2022-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-13
      相关资源
      最近更新 更多