如何使用curl php在框中上传文件或文件夹。

时间:2017-05-12 06:52:24

标签: php curl box

我想将图片上传到我的盒子帐户到它的根文件夹。 我怎样才能实现这一点。下面是我的代码,请检查。

https://upload.box.com/api/2.0/files/content

    $json = json_encode(array(
                        'name' => 'spring.jpg', 
                        'folder' => array('id' =>'0')// 0 - uploads to main folder
                        ));
    $fields = array(
                  'attributes' => $json,
                  'file'=> new CURLFile('@C:\xampp\htdocs\box\spring.jpg')
              );

    $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',          
        'Authorization: Bearer W1UkcTHsuuiDCA3Ej5n4xwMqoSGh0iVW'));
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_VERBOSE, true);

        var_dump($fields);

        $response = curl_exec($ch);
        curl_close($ch);
        print_r($response);

0 个答案:

没有答案