15年软件开发经验 只做源码定制 互联网+定制化解决方案

15年软件开发经验,只做源码定制!

原创设计 定制开发

满足您的个性化需求

当前位置:首页 后端开发 Thinkphp5

Dropbox API,国外上传文件夹,上传到远程文件,

教腾豪| 发布于 2021-09-27 18:00:00| 152阅读| 0点赞| 0评论
举报

Dropbox API,上传文件夹,生成文件夹,

用PHP_curl去请求dropbox

dropbox API https://www.dropbox.com/developers/documentation/http/documentation



function create_dropbox_folder($foldername)

{

    if(isset($foldername)){

        //查询文件

        $data=[

            'query'=>$foldername,//文件名称

            'options'=>['path'=>"/TaxAct Client List/A-2021 Client Doc"]//多选字段 path 文件路径

        ];

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        curl_setopt($ch, CURLOPT_URL, 'https://api.dropboxapi.com/2/files/search_v2');

        curl_setopt($ch, CURLOPT_HTTPHEADER, [

            "Content-Type: application/json",

            'Authorization: Bearer WEOR0m62p_QAAAAAAAAAAaE2ScoPo8uB5q-MvMsUUuGkEZ1N7bELP65BRgH0pLo3'

        ]);

        if($data) {

            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

        }

        curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "POST");

        $result = curl_exec($ch);

        curl_close($ch);

        if(empty(json_decode($result)->matches))

        {

            $path=[

                'paths'=>

                    ["/TaxAct Client List/A-2021 Client Doc/".$foldername,

                        "/TaxAct Client List/A-2021 Client Doc/".$foldername."/Client Download",

                        "/TaxAct Client List/A-2021 Client Doc/".$foldername."/Client Uploaded",

                        "/TaxAct Client List/A-2021 Client Doc/".$foldername."/Organized Client Upload",

                    ]

            ];

            // 创建多个文件

            $ch = curl_init();

            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

            curl_setopt($ch, CURLOPT_URL, 'https://api.dropboxapi.com/2/files/create_folder_batch');

            curl_setopt($ch, CURLOPT_HTTPHEADER, [

                "Content-Type: application/json",

                'Authorization: Bearer WEOR0m62p_QAAAAAAAAAAaE2ScoPo8uB5q-MvMsUUuGkEZ1N7bELP65BRgH0pLo3'

            ]);



            if($path) {

                curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($path));

            }

            curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "POST");

            $result = curl_exec($ch);

            curl_close($ch);

            $paths=[

                'entries'=>[

                    [

                        'from_path'=>"/TaxAct Client List/A-2021 Client Doc/A-Archive/A-First Last Name_Email/Prepared Forms",

                        'to_path'=>"/TaxAct Client List/A-2021 Client Doc/".$foldername."/Prepared Forms"

                    ],

                ],

                "autorename"=>true

            ];

            // 创建多个文件

            $ch = curl_init();

            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

            curl_setopt($ch, CURLOPT_URL, 'https://api.dropboxapi.com/2/files/copy_batch_v2');

            curl_setopt($ch, CURLOPT_HTTPHEADER, [

                "Content-Type: application/json",

                'Authorization: Bearer WEOR0m62p_QAAAAAAAAAAaE2ScoPo8uB5q-MvMsUUuGkEZ1N7bELP65BRgH0pLo3'

            ]);

            if($paths) {

                curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($paths));

            }

            curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "POST");

            $results = curl_exec($ch);

            curl_close($ch);

            if(isset(json_decode($results,true)['async_job_id'])){

                $data=['async_job_id'=><a href="https://www.qinfenniao.com/article.html?name=js" target="_blank">js</a>on_decode($results,true)['async_job_id']];

                $ch = curl_init();

                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

                curl_setopt($ch, CURLOPT_URL, 'https://api.dropboxapi.com/2/files/copy_batch/check_v2');

                curl_setopt($ch, CURLOPT_HTTPHEADER, [

                    "Content-Type: <a href="https://www.qinfenniao.com/nav/%E7%BD%91%E7%AB%99%E5%BC%80%E5%8F%91.html" target="_blank">app</a>lication/<a href="https://www.qinfenniao.com/article.html?name=js" target="_blank">js</a>on",

                    'Authorization: Bearer WEOR0m62p_QAAAAAAAAAAaE2ScoPo8uB5q-MvMsUUuGkEZ1N7bELP65BRgH0pLo3'

                ]);

                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

                if($data) {

                    curl_setopt($ch, CURLOPT_POSTFIELDS, <a href="https://www.qinfenniao.com/article.html?name=js" target="_blank">js</a>on_encode($data));

                }

                curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "POST");

                $ss = curl_exec($ch);

                curl_close($ch);

            }

        }

    }

}



先查询出来文件

//查询文件

        $data=[

            'query'=>$foldername,//文件名称

            'options'=>['path'=>"/TaxAct Client List/A-2021 Client Doc"]//多选字段 path 文件路径

        ];


创建文件夹

 $path=[

                'paths'=>

                    ["/TaxAct Client List/A-2021 Client Doc/".$foldername,

                        "/TaxAct Client List/A-2021 Client Doc/".$foldername."/Client Download",

                        "/TaxAct Client List/A-2021 Client Doc/".$foldername."/Client Uploaded",

                        "/TaxAct Client List/A-2021 Client Doc/".$foldername."/Organized Client Upload",

                    ]

            ];

            // 创建多个文件

            $ch = curl_init();

            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

            curl_setopt($ch, CURLOPT_URL, 'https://api.dropboxapi.com/2/files/create_folder_batch');

            curl_setopt($ch, CURLOPT_HTTPHEADER, [

                "Content-Type: <a href="https://www.qinfenniao.com/nav/%E7%BD%91%E7%AB%99%E5%BC%80%E5%8F%91.html" target="_blank">app</a>lication/<a href="https://www.qinfenniao.com/article.html?name=js" target="_blank">js</a>on",

                'Authorization: Bearer WEOR0m62p_QAAAAAAAAAAaE2ScoPo8uB5q-MvMsUUuGkEZ1N7bELP65BRgH0pLo3'

            ]);


路径必须是根目录,文件名称和位置不能出错

0

0条评论

别默默看啦~登录/注册一起参与讨论吧~

热门标签

教腾豪
微信扫一扫立即咨询
账号登录|扫码登录

立即注册 |忘记密码?

欢迎注册

已有账号马上登录

重置密码

扫码绑定微信
微信扫一扫

绑定手机号

分享到-微信

举报

  • 举报类型:

  • 举报描述:

您好,当前积分不足。

在线客服
拨打电话
17330196230 13230981129
顶部