在本页面:http://developers.box.com/docs/
使用 cURL 上传文件:
METHOD
POST /files/content
EXAMPLE REQUEST
curl https://api.box.com/2.0/files/content \
-H "Authorization: BoxAuth api_key=API_KEY&auth_token=AUTH_TOKEN" \
-F filename1=@FILE_NAME1 \
-F filename2=@FILE_NAME2 \
-F folder_id=FOLDER_ID
但是现在,我想使用 php 上传文件,我该怎么做呢?我的代码:
<?php
$params = array();
$params['folder_id'] = '485272014';
$u_file = fopen("D:\code\php\bcs\test.data", "r");
$params['filename1'] = $u_file;
$params = json_encode($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.box.com/2.0/files/content");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_UPLOAD, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: BoxAuth api_key=API_KEY&auth_token=TOKEN"));
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
fclose($u_file);
?>
它没有用,我使用以下命令运行脚本:php -f test.php