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
$params['filename1'] = "@D:\code\php\bcs\test.data";
- GBD